@contentgrid/problem-details
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

@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);
        }
    })

Package Sidebar

Install

npm i @contentgrid/problem-details

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

12.6 kB

Total Files

8

Last publish

Collaborators

  • xenit-jenkins