The logger exchanges are reported to, for instance the platform console
Optional Readonlybusy?: (status: boolean) => unknownTakes true as the client turns busy and false as it turns idle again
Optional Readonlyinfo?: (message: string) => unknownTakes an entry reporting a request as it is sent or a response served from a cache
Optional 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 performedAlongside the entries, the busy status of the client is stated to
logger.busy:trueas the first exchange is relayed andfalseas the last one in flight is answered or fails, so that a waiting indicator is driven without the call sites keeping count. A request stating a malformed URL is answered without being sent, so it leaves the busy status untouched.A logger takes on only the concerns it is interested in: every member is optional and whatever it doesn't state is not reported.
Requests 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.