cencori 1.7.4 → 1.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1880,8 +1880,12 @@ async function request(config, method, path, body, extraHeaders, options) {
1880
1880
  });
1881
1881
  if (!response.ok) {
1882
1882
  const errorData = await response.json().catch(() => ({ error: "Unknown error" }));
1883
- const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message || response.statusText;
1883
+ const message = typeof errorData.error === "string" ? errorData.error : errorData.error?.message ?? (typeof errorData.message === "string" ? errorData.message : null) ?? response.statusText;
1884
1884
  const details = typeof errorData.error === "object" ? errorData.error : null;
1885
+ const topCode = typeof errorData.code === "string" ? errorData.code : null;
1886
+ const topRequestId = typeof errorData.request_id === "string" ? errorData.request_id : typeof errorData.requestId === "string" ? errorData.requestId : null;
1887
+ const topType = typeof errorData.type === "string" ? errorData.type : null;
1888
+ const topParam = typeof errorData.param === "string" ? errorData.param : null;
1885
1889
  let retryAfterSeconds = parseRetryAfterSeconds(response.headers.get("Retry-After") ?? response.headers.get("retry-after"));
1886
1890
  if (retryAfterSeconds == null) {
1887
1891
  const secHint = details?.retry_after_seconds ?? errorData.retry_after_seconds ?? details?.retry_after ?? errorData.retry_after;
@@ -1894,7 +1898,7 @@ async function request(config, method, path, body, extraHeaders, options) {
1894
1898
  }
1895
1899
  }
1896
1900
  }
1897
- throw new CencoriEmbeddedApiError(message, response.status, details?.code ?? null, details?.request_id ?? response.headers.get("X-Request-Id"), details?.type ?? null, details?.param ?? null, retryAfterSeconds);
1901
+ throw new CencoriEmbeddedApiError(message, response.status, details?.code ?? topCode, details?.request_id ?? topRequestId ?? response.headers.get("X-Request-Id"), details?.type ?? topType, details?.param ?? topParam, retryAfterSeconds);
1898
1902
  }
1899
1903
  if (response.status === 204) return void 0;
1900
1904
  return response.json();