UNPKG

problem-details

Version:

HTTP problem details model based on RFC7807

34 lines (26 loc) 953 B
# Problem Details [![npm version](https://badge.fury.io/js/problem-details.svg)](https://badge.fury.io/js/problem-details) HTTP problem details model based on [RFC7807](https://tools.ietf.org/html/rfc7807). This package wraps the default `Error` object to throw better defined errors which are previously registered. This ensures that thrown errors are more consistent. ### Install ```bash npm install --save problem-details ``` ### Basic Example ```javascript import { ProblemDefinition, DetailFactory, DefinitionFactory } from 'problem-details'; // setup definition factory const definitionFactory = new DefinitionFactory(); definitionFactory.load([ { code: 'C001', status: 400, title: 'You do not have enough credit', type: 'https://www.example.com/support/C001' } ]); // setup detail factory const detailFactory = new DetailFactory(definitionFactory); // ... // throw error throw detailFactory.createFromCode('C001'); ```