Function: normalizeHttpError()
@providerprotocol/ai / http / normalizeHttpError
Function: normalizeHttpError()
Section titled “Function: normalizeHttpError()”normalizeHttpError(
response,provider,modality):Promise<UPPError>
Defined in: src/http/errors.ts:100
Normalizes HTTP error responses into standardized UPPError objects.
This function performs several operations:
- Maps the HTTP status code to an appropriate ErrorCode
- Attempts to extract a meaningful error message from the response body
- Handles various provider-specific error response formats
Supported error message formats:
{ error: { message: "..." } }(OpenAI, Anthropic){ message: "..." }(simple format){ error: { error: { message: "..." } } }(nested format){ detail: "..." }(FastAPI style)- Plain text body (if under 200 characters)
Parameters
Section titled “Parameters”response
Section titled “response”Response
The HTTP Response object with non-2xx status
provider
Section titled “provider”string
Provider identifier for error context
modality
Section titled “modality”Request modality for error context
Returns
Section titled “Returns”Promise<UPPError>
A UPPError with normalized code and message
Example
Section titled “Example”if (!response.ok) { const error = await normalizeHttpError(response, 'openai', 'llm'); // error.code might be 'RATE_LIMITED' for 429 // error.message contains provider's error message throw error;}