Creates a middleware admitting only 2xx responses, reporting failures as problems.
Decorates a Fetch implementation with one reporting every failure as a single structured exception, so that
callers await a usable response rather than inspecting response.ok at each call site:
Response is ok (2xx status): the promise resolves with the response unchanged
Response is not ok (non-2xx status): the promise rejects with a Problem carrying the response
status and its statusText as detail, plus the body as report when the Content-Type allows it to be read:
text/plain: the body as text
JSON-based media types, for example application/json, application/ld+json or application/problem+json: the
parsed JSON payload
other media types, or a body that fails to parse: no report
The wrapped implementation rejects with an Error (network failures, timeouts, CORS denials): the promise
rejects with a Problem carrying status 0 and a rendering of the error as detail
The wrapped implementation rejects with any other value (typically a Problem raised by an inner
layer): the value is relayed unchanged
Problems reported by this middleware are immutable, so a handler may pass one on without guarding against
later mutation.
Note
The middleware is idempotent: applying it more than once to the same chain is harmless, as a Problem
raised by an inner layer is relayed unchanged rather than reported again as a transport failure.
Creates a middleware admitting only 2xx responses, reporting failures as problems.
Decorates a Fetch implementation with one reporting every failure as a single structured exception, so that callers await a usable response rather than inspecting
response.okat each call site:ok(2xxstatus): the promise resolves with the response unchangedok(non-2xxstatus): the promise rejects with a Problem carrying the responsestatusand itsstatusTextasdetail, plus the body asreportwhen theContent-Typeallows it to be read:text/plain: the body as textapplication/json,application/ld+jsonorapplication/problem+json: the parsed JSON payloadreportError(network failures, timeouts, CORS denials): the promise rejects with a Problem carryingstatus0 and a rendering of the error asdetailProblems reported by this middleware are immutable, so a handler may pass one on without guarding against later mutation.
The middleware is idempotent: applying it more than once to the same chain is harmless, as a Problem raised by an inner layer is relayed unchanged rather than reported again as a transport failure.