From dec2819f9baf43bd4e892bc0d434b6457169ab4b Mon Sep 17 00:00:00 2001 From: Jason Date: Sat, 21 Mar 2026 23:50:02 +0100 Subject: [PATCH] fix(error): fall back to full response body when error field is absent When an OpenAI-compatible API returns an error response that does not include an `error` field (e.g. using `detail` or other custom fields), the Node.js client previously produced unhelpful messages like "422 status code (no body)". This fix mirrors the Python client behavior: if `body.error` is not present, the entire response body is used as the error detail. The existing `makeMessage` logic already handles this case by calling JSON.stringify on non-string error values, so downstream error messages will now include the full response body when no `error` field is found. --- src/core/error.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/error.ts b/src/core/error.ts index 723a15dd1..6451e6a63 100644 --- a/src/core/error.ts +++ b/src/core/error.ts @@ -66,7 +66,7 @@ export class APIError< return new APIConnectionError({ message, cause: castToError(errorResponse) }); } - const error = (errorResponse as Record)?.['error']; + const error = (errorResponse as Record)?.['error'] ?? errorResponse; if (status === 400) { return new BadRequestError(status, error, message, headers);