@metreeca/http - v0.1.1
    Preparing search index...

    Function monitor

    • 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:

      • Request states a malformed URL (only a raw string may): reported to logger.warn and answered with a network error Response, without being sent
      • Request is sent: reported to logger.info
      • Response is not ok (non-2xx status): its status and statusText are reported to logger.warn
      • Response is ok (2xx status) and served from a cache: its status is reported to logger.info, alongside a note stating the content came from a cache, as told by the Age field only a cache states
      • Response is ok (2xx status) and served by the origin: nothing further is reported, leaving a plain exchange to the single entry stating it was performed

      Requests are inspected as they are stated, rather than normalised into Request objects, 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.

      Parameters

      • logger: { info: (message: string) => unknown; warn: (message: string) => unknown }

        The logger exchanges are reported to, for instance the platform console

        • Readonlyinfo: (message: string) => unknown

          Takes an entry reporting a request as it is sent or a response served from a cache

        • Readonlywarn: (message: string) => unknown

          Takes an entry reporting a request stating a malformed URL or an unsuccessful response

      Returns Middleware

      A Middleware reporting every exchange it relays to logger, answering a request stating a malformed URL with a network error without sending it