0.0.7 • Published 4 years ago

problem-details v0.0.7

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

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