Skip to main content

readErrorBody

Callable


  • Parse a non-OK response body as a TwinErrorBody. Falls back to a synthetic body carrying the response text (or statusText) when the body isn't valid JSON — for example when a WAF or intermediate proxy injects an HTML 4xx page. Callers can therefore always pattern-match on errorBody.cause without an outer try/catch around a bare response.json().

    The synthetic body uses cause: 'Unknown', which is permitted by the (string & {}) forward-compat tail on TwinErrorCause. Consumers that switch on known causes will fall through to a default arm.


    Parameters

    • response: Response

    Returns Promise<TwinErrorBody>