Skip to content

toErrorResponse

toErrorResponse(response, fallbackCode): AuthResponse<never>

Defined in: packages/auth/src/errors/toErrorResponse.ts:20

Convert a RestClient response into an error-shaped AuthResponse.

Three cases, in priority order:

  1. Body is the normalized APIResponse shape with isErr: true — map errorCode via mapBackendErrorCode; if no specific mapping is found, fall back to the caller-supplied fallbackCode so each call site stays in control of its default failure code.
  2. apisauce flagged a transport problem (timeout / network / connection error) — return AUTH_NETWORK_ERROR. HTTP 401 falls through to AUTH_UNAUTHORIZED.
  3. Anything else — fall back to the caller-supplied fallbackCode.

RestResponse<unknown>

AuthErrorCode

AuthResponse<never>