Package Exports
- any-restapi-errors
- any-restapi-errors/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (any-restapi-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
How do you use it? Throw it in your code when you want to any errors
try {
if (user === null) {
throw new apiError(404);
// or with name as well throw new apiError(404,"details");
}
} catch (error) {
// Log the error using the custom error logger
error.errorLogger();
res.status(error.statusCode || 500).send({
error: {
name: error.name,
message: error.message,
statusCode: error.statusCode,
isOperational: error.isOperational
}
});
}Error Logger
error logger
- when you use
error.errorLogger();method it will create error.log file and logs details like isOperational, level, message, service,stack. - Following Json object example will be created in error.log file when error will occure.
{"isOperational":true,"level":"error","message":"Not found.","service":"user-service","stack":"Error: Not found.\n at new BaseError (file:///D:/npm-error/baseError.js:11:8)\n ,"statusCode":404}