All files / core/blong-gogo/src gatewayCaught.ts

86.66% Statements 13/15
100% Branches 4/4
50% Functions 1/2
86.66% Lines 13/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 161x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 136x      
/**
 * gatewayCaught.ts — the error a failed gateway call raises, whichever way it arrived.
 *
 * A dispatch answers a failure as a packet: `[error, $meta]`. Most callers unwrap it and rethrow the
 * first element, but one path rethrows the packet itself, and the gateway then read an array where it
 * expected an error — no `type`, no `statusCode`, so a refusal that declared 400 answered 500 with an
 * error object the client could only render as `{}` (`@@F-720`).
 *
 * The shape says what it is, so the unwrapping lives here rather than at every place that can answer
 * that way: a packet is an array whose first element is what the caller wanted.
 */
export const caughtError = (caught: unknown): unknown =>
    Array.isArray(caught) && caught.length ? caught[0] : caught;

export default caughtError;