lambda-errors-formatter
v0.5.0
Published
AWS Lambda errors formatter
Downloads
7
Readme
Lambda errors formatters
An errors formatter for managing lambda error response
Installation
npm install lambda-errors-formatter --save
Usage
const errorFormatter = require('lambda-errors-formatter')
errorFormatter.format('error message')
errorFormatter.format({
statusCode: 400,
message: 'error message'
})
Response
{
statusCode: 'error code',
body: "{message: 'error message'}",
headers: {
'Access-Control-Allow-Origin' : '*',
'Content-Type': 'application/json'
}
}
Other functions
Format error with custom code
errorFormatter.formatCode(400, 'error message')
Bad request
errorFormatter.badRequest('error message') //status code 400
Unauthorized
errorFormatter.unauthorized('error message') //status code 401
Forbidden
errorFormatter.forbidden('error message') //status code 403
Not found
errorFormatter.notFound('error message') //status code 404
Conflict
errorFormatter.conflict('error message') //status code 409
Internal server error
errorFormatter.internalServerError('error message') //status code 500
Tests
npm test
Coverage
npm run-script test-travis