Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
/ problem-details Public archive

HTTP problem details model based on RFC7808

Notifications You must be signed in to change notification settings

jorenkoyen/problem-details

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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