{"record":{"id":"0e3a8fab3afab8b8","repo":"vercel/ai","slug":"failed-to-process-error-response","errorCode":null,"errorMessage":"Failed to process error response","messagePattern":"Failed to process error response","errorType":"exception","errorClass":"APICallError","httpStatus":null,"severity":"error","filePath":"packages/provider-utils/src/get-from-api.ts","lineNumber":116,"sourceCode":"\n    if (!response.ok) {\n      let errorInformation: {\n        value: Error;\n        responseHeaders?: Record<string, string> | undefined;\n      };\n\n      try {\n        errorInformation = await failedResponseHandler({\n          response,\n          url,\n          requestBodyValues: {},\n        });\n      } catch (error) {\n        if (isAbortError(error) || APICallError.isInstance(error)) {\n          throw error;\n        }\n\n        throw new APICallError({\n          message: 'Failed to process error response',\n          cause: error,\n          statusCode: response.status,\n          url,\n          responseHeaders,\n          requestBodyValues: {},\n        });\n      }\n\n      throw errorInformation.value;\n    }\n\n    try {\n      return await successfulResponseHandler({\n        response,\n        url,\n        requestBodyValues: {},\n      });","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/provider-utils/src/get-from-api.ts#L98-L134","documentation":"getFromApi received an error-status HTTP response, but while building/processing the APICallError from the error body, an unexpected exception occurred. The library wraps that unexpected parsing/processing failure in a new APICallError with this message, preserving the original failure as `cause`. It signals that the provider's error response could not be handled normally (e.g. non-JSON error body).","triggerScenarios":"A fetch inside getFromApi returned a non-2xx status, and the code path that parses the error body (e.g. safeParseJSON of the response or constructing APICallError) threw something that is neither an AbortError nor an APICallError — such as a body-stream read failure or an unexpected runtime exception in response processing.","commonSituations":"Provider returns an HTML error page (proxy/CDN 502 page) instead of JSON; the response body stream errors mid-read; a corrupted or truncated error response; custom fetch implementations returning malformed Response objects.","solutions":["Inspect `error.cause` (and the original provider response if logged) to find the underlying failure","Check whether a proxy, gateway, or custom `fetch` is returning non-JSON error bodies (HTML error pages)","Retry the request; if intermittent, it may be a transient network/gateway problem","Capture the full error (message, cause, url, statusCode) and report to the provider package maintainers if the error body is valid JSON yet still fails"],"exampleFix":"// inspecting the wrapped failure\ntry {\n  await result;\n} catch (error) {\n  if (APICallError.isInstance(error) && error.message === 'Failed to process error response') {\n    console.error('underlying cause:', error.cause, 'status:', error.statusCode, 'url:', error.url);\n  }\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isFailedToProcessErrorResponse(e: unknown): e is APICallError {\n  return APICallError.isInstance(e) && e.message === 'Failed to process error response';\n}","tryCatchPattern":"try {\n  await getFromApi({ url, successfulResponseHandler: ... });\n} catch (error) {\n  if (isAbortError(error) || APICallError.isInstance(error)) {\n    console.error('status:', error.statusCode, 'cause:', error.cause);\n  }\n}","preventionTips":["Use the built-in provider functions rather than hand-rolled fetch so errors are wrapped consistently","Always inspect error.cause for the real underlying failure","Watch for proxies/CDNs returning HTML error pages and handle them upstream"],"tags":["network","http","api-response","provider"],"backgroundTag":"api-error-response-parse-failed","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}