The logger exchanges are logged 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 stating a sent request, a response served from a cache or an aborted exchange
Optional Readonlywarn?: (message: string) => unknownTakes an entry stating an unsuccessful response or a failed exchange
A Middleware logging every exchange it relays to logger
Creates an exchange monitoring middleware.
Wraps a Fetch implementation, logging every exchange it relays and leaving the exchange itself untouched.
Every entry opens with the method and the target URL of the exchange. The method is stated in uppercase and the URL is clipped, so that entries stay uniform and on a single line. An exchange is logged as it is sent. It is logged once more as it settles, unless it ends with a successful response served by the origin server:
logger.info, with a malformed URL logged as statedok(non-2xxstatus): itsstatusandstatusTextare logged tologger.warn, followed by the error type itsProxy-Statusfield states, if any, enclosed in square bracketsok(2xxstatus) and served from a cache: itsstatusis logged tologger.info, with a note stating that the content came from a cache, as told by theAgeheader field that only a cache adds to a responseok(2xxstatus) and served by the origin: nothing further is logged, as the entry stating the request was sent already covers the whole of a plain exchange with the origin serverlogger.warn, followed by thecodeor else the message of itscause, if any, and the failure is then relayed as it standslogger.infoand relayed as it standsThe busy status of the client is stated to
logger.busyas well. It turnstrueas the first exchange is relayed andfalseas the last one in flight settles, whether it failed or not. A waiting indicator is thus driven without the call sites keeping count. A request stating a malformed URL is never sent, so it leaves the busy status as it is.Every member of the logger is optional, and whatever a logger leaves out is not logged.
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.With resolve declared below this middleware, failed exchanges reach it as responses stating why they failed. A malformed URL is then logged with the
400answering it, and a refused connection with the502and theconnection_refusederror type stated in theProxy-Statusfield answering it.