npm.io
0.4.5 • Published 2 weeks ago

@contentgrid/problem-details

Licence
MIT
Version
0.4.5
Deps
2
Size
10 kB
Vulns
0
Weekly
0
Stars
1

@contentgrid/problem-details

RFC 9457 Problem Details types and helpers

Usage

import { ProblemDetail, ProblemDetailError, checkResponse } from '@contentgrid/problem-details'

// Fetch data from somewhere
fetch('/some-url')
    .then(checkResponse) // Throws ProblemDetailError if an error response is returned
    .then(response => {
        // Handle succesfull response
    }, error => {
        // Handle error response
        if(error instanceof ProblemDetailError) {
            // ProblemDetail is available on the ProblemDetailError
            console.error("Failed to fetch", error.problemDetail.title)
        } else {
            console.error("Failed to fetch", error);
        }
    })

Keywords