Skip to content

Customized error class module for projects/microservices. Throw error objects within a JavaScript Error class while preserving the stack (https://www.npmjs.com/package/project-error)

License

Notifications You must be signed in to change notification settings

suddi/project-error

Repository files navigation

ProjectError

CircleCI codecov Codacy Badge npm npm David David license

codecov

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

  1. Pass any object containing into the first argument of ProjectError:
var ProjectError = require('project-error');

throw new ProjectError({
    code: 4010,
    statusCode: 400,
    message: 'Bad Request'
});
  1. Pass additional error details as either a string or an array of strings:
var ProjectError = require('project-error');

var errorObj = {
    code: 4010,
    statusCode: 400,
    message: 'Bad Request'
};
var errorDetail = 'This is a one-liner error detail';
throw new ProjectError(errorObj, errorDetail);
var ProjectError = require('project-error');

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 new ProjectError(errorObj, errorDetails);
  1. 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 = new Error('Fail!');
throw new ProjectError(errorObj, errorDetail, error);

About

Customized error class module for projects/microservices. Throw error objects within a JavaScript Error class while preserving the stack (https://www.npmjs.com/package/project-error)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published