Skip to content

Function: normalizeHttpError()

@providerprotocol/ai


@providerprotocol/ai / http / 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:

  1. Maps the HTTP status code to an appropriate ErrorCode
  2. Attempts to extract a meaningful error message from the response body
  3. 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)

Response

The HTTP Response object with non-2xx status

string

Provider identifier for error context

Modality

Request modality for error context

Promise<UPPError>

A UPPError with normalized code and message

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;
}