@metreeca/core - v0.9.17
    Preparing search index...

    Function createFetch

    • Creates a fetch function with consistent promise resolution/rejection behavior.

      Wraps a fetch function to provide consistent, sensible promise semantics where successful responses resolve and all errors reject with structured Problem exceptions:

      • Response is ok (2xx status): Promise resolves with the response unchanged
      • Response is not ok (non-2xx status): Response body is read according to Content-Type, converted to Problem, and promise rejects:
        • text/plain: Response body as text in report field
        • JSON-based MIME types (e.g., application/json, application/ld+json, application/problem+json): Parsed JSON payload in report field
        • Other content types: status code and statusText only
      • Fetch exception occurs (network errors, timeouts, CORS failures): Exception is converted to Problem with status 0 and promise rejects

      If response body parsing fails, promise rejects with Problem containing the original response status and statusText.

      Parameters

      • base: {
            (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
            (input: string | Request | URL, init?: RequestInit): Promise<Response>;
        }

        The fetch function to wrap

          • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: RequestInfo | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | Request | URL, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | Request | URL
            • Optionalinit: RequestInit

            Returns Promise<Response>

      Returns {
          (input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
          (input: string | Request | URL, init?: RequestInit): Promise<Response>;
      }

      Fetch function whose promises reject with Problem for all error conditions

        • (input: RequestInfo | URL, init?: RequestInit): Promise<Response>
        • Parameters

          • input: RequestInfo | URL
          • Optionalinit: RequestInit

          Returns Promise<Response>

        • (input: string | Request | URL, init?: RequestInit): Promise<Response>
        • Parameters

          • input: string | Request | URL
          • Optionalinit: RequestInit

          Returns Promise<Response>