HttpErrorMapper

org.llm4s.llmconnect.provider.HttpErrorMapper
@Stable

Shared HTTP status-code to org.llm4s.error.LLMError mapping used by all HTTP-based LLM provider clients.

Centralises the duplicated pattern of converting non-2xx responses into typed Result errors. Provider-specific error details are extracted from the JSON response body when possible and truncated to a safe length.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def mapHttpError(statusCode: Int, body: String, provider: String, headers: Map[String, Seq[String]]): Result[Nothing]

Maps an HTTP error response to a typed org.llm4s.error.LLMError.

Maps an HTTP error response to a typed org.llm4s.error.LLMError.

Status Error
401, 403 org.llm4s.error.AuthenticationError
429 org.llm4s.error.RateLimitError, with retryAfter from Retry-After
400 org.llm4s.error.ValidationError
other org.llm4s.error.ServiceError

A 429's Retry-After header (delta-seconds or an HTTP-date, name matched case-insensitively) becomes the error's retryAfter duration; an absent, unparseable or negative value leaves it unset, so the error's default backoff applies.

Value parameters

body

the raw response body (may be JSON or plain text)

headers

the response headers, as carried by org.llm4s.http.HttpResponse; pass them whenever the response is available

provider

short provider label used in error messages (e.g. "gemini")

statusCode

the HTTP status code (must be outside 2xx range)

Attributes

Returns

Left containing the appropriate LLMError subtype