Skip to content

joblocal/middy-json-api-error-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Middy JSON API Error Handler

This is a middy middleware, which is formatting errors as error responses according to the JSON:API spec.

Installation

npm install @joblocal/middy-json-api-error-handler

Usage

# handler.js
const middy = require('middy');
const jsonApiErrorHandler = require('@joblocal/middy-json-api-error-handler');

const yourHandler = () => {
  throw new Error({
    code: '123',
    source: { 'pointer': '/data/attributes/first-name' },
    title: 'Value is too short',
    detail: 'First name must contain at least three characters.'
  });
};

const handler = middy(yourHandler)
  .use(jsonApiErrorHandler());

module.exports = { handler };

About

A middy middleware to format errors as json api errors.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published