@grafctory/http - v0.9.0
    Preparing search index...

    Module reject

    Unsuccessful response rejection middleware.

    Admits only 2xx responses from the wrapped Fetch implementation, rejecting the others as problems. Paired with resolve declared below it, transport failures are rejected as problems too, 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.

    It is the converse of resolve, which turns failed exchanges into responses.

    Usage

    import { createFetch, NotFound } from "@grafctory/http";
    import { reject } from "@grafctory/http/reject";
    import { resolve } from "@grafctory/http/resolve";

    const client = createFetch(
    reject(), // rejects unless response.ok
    resolve() // declared below reject: transport failures are rejected as problems too
    );

    try {

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

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

    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.

    reject

    Creates a middleware admitting only 2xx responses, rejecting the others as problems.