The logger exchanges are reported to, for instance the platform console
Readonlyinfo: (message: string) => unknownTakes an entry reporting a request as it is sent or a response served from a cache
Readonlywarn: (message: string) => unknownTakes an entry reporting a request stating a malformed URL or an unsuccessful response
A Middleware reporting every exchange it relays to logger, answering a request stating a
malformed URL with a network error without sending it
Creates an exchange monitoring middleware.
Wraps a Fetch implementation, reporting every exchange as it is performed and leaving requests and responses otherwise untouched.
Every entry opens with the method and the target URL of the exchange, the method reported in uppercase and the URL clipped so that entries stay uniform and on a single line, and states the outcome once the response is in:
logger.warnand answered with a network errorResponse, without being sentlogger.infook(non-2xxstatus): itsstatusandstatusTextare reported tologger.warnok(2xxstatus) and served from a cache: itsstatusis reported tologger.info, alongside a note stating the content came from a cache, as told by theAgefield only a cache statesok(2xxstatus) and served by the origin: nothing further is reported, leaving a plain exchange to the single entry stating it was performedRequests are inspected as they are stated, rather than normalised into
Requestobjects, so that a body carried by the request reaches the layers below untouched.Exchanges are reported as the caller states them, so the middleware is best declared first in a chain: a malformed URL is screened out before it reaches a layer that would reject it outright, at the cost of reporting a request as it was stated rather than as the layers below leave it.