ProjectError
Customized error class module for project/microservices. Throw error enum objects within a JavaScript Error class preserving the stack.
Installation
npm install --save project-error
Usage
- Pass any object containing into the first argument of
ProjectError
:
var ProjectError = ; throw code: 4010 statusCode: 400 message: 'Bad Request';
- Pass additional error details as either a string or an array of strings:
var ProjectError = ; var errorObj = code: 4010 statusCode: 400 message: 'Bad Request';var errorDetail = 'This is a one-liner error detail';throw errorObj errorDetail;
var ProjectError = ; var errorObj = code: 4010 statusCode: 400 message: 'Bad Request';var errorDetails = 'This is multiple lines of error details' 'This is multiple lines of error details' 'This is multiple lines of error details';throw errorObj errorDetails;
- Pass a standard
Error
object and preserve the stack:
var errorObj = code: 4010 statusCode: 400 message: 'Bad Request';var errorDetail = 'This is a one-liner error detail';var error = 'Fail!';throw errorObj errorDetail error;