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

0.0.7 • Public • Published

Problem Details

npm version

HTTP problem details model based on 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

npm install --save problem-details

Basic Example

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');

Package Sidebar

Install

npm i problem-details

Weekly Downloads

4

Version

0.0.7

License

ISC

Unpacked Size

42 kB

Total Files

55

Last publish

Collaborators

  • jorenkoyen