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
401without reading the body. A401often 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.