RestErrorMapper

class RestErrorMapper<E : ErrorSpec, P : Any>(payloadType: TypeInfo, val unauthorized: E? = null, val apiError: (P, HttpStatusCode) -> E, val networkError: (Throwable) -> E, val parseError: (Throwable) -> E)(source)

Maps every failure of a TypedRestClient call to the caller's error type E.

  • apiError maps a non-2xx response: its body decoded as the error payload P, and its status.

  • unauthorized, when set, is raised on a 401 without reading the body. A 401 often comes from a gateway or an identity provider, not from the API, so its body is rarely a P.

  • networkError wraps a request that could not be sent; parseError wraps a body, success or error, that could not be decoded.

The payload decodes through the client's own content negotiation, like a success body, so the mapper holds no codec. Build one with of, which captures P by reification, or take default.

Constructors

Link copied to clipboard
constructor(payloadType: TypeInfo, unauthorized: E? = null, apiError: (P, HttpStatusCode) -> E, networkError: (Throwable) -> E, parseError: (Throwable) -> E)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val apiError: (P, HttpStatusCode) -> E
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
suspend fun errorOf(response: HttpResponse): E

The E for a non-2xx response: unauthorized on a 401 when set, else apiError over the decoded body.