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

    Module success

    Uniform failure reporting middleware.

    Admits only 2xx responses from the wrapped Fetch implementation, reporting error responses and transport failures alike as problems, so that a failed exchange is handled in one shape whatever caused it.

    The same shape is available on its own to code handling failures raised elsewhere: any value may be recognised as a problem, or normalised into one, so that a handler branches on problem details without first telling apart what it was handed.

    Usage

    import { createFetch, NotFound } from "@metreeca/http";
    import { success } from "@metreeca/http/success";

    const client = createFetch(success()); // rejects unless response.ok

    try {

    const response = await client("https://api.example.com/data");

    } catch ( problem ) { // a Problem, whatever went wrong

    if ( problem.status === NotFound ) { // handle a missing resource
    }

    }
    Problem

    Problem details for HTTP APIs.

    isProblem

    Checks if a value is a Problem.

    toProblem

    Converts a value to a Problem.

    success

    Creates a middleware admitting only 2xx responses, reporting failures as problems.