xcore-express
v1.0.1
Published
A lightweight library that brings middlewares to handle error reporting in web applications using Node and Express.
Downloads
4
Maintainers
Readme
xcore-express
A lightweight library that brings middlewares to handle error reporting in web applications using Node and Express.
Guide
A reference guide to middlewares and helper functions included in xcore.
Exception Classes
Middlewares
ErrorHandler
A middleware to detect error type and send a JSON response with approperiate HTTP Status code and message.
Usage:
if (!req.isAuthenticated()) {
throw new UnauthenticatedException("Authentication is required.");
}
Example response:
{
"meta": {
"code": 401,
"success": false,
"message": "Authentication is required."
}
}
Logger
A middleware to format and log errors to console.
Sample console log:
>> GET /api/users/me
>> [UnauthenticatedException] Authentication is required.
>> [Error]
>> ... stack trace ...
Creator
License
xcore-express is released under the MIT license. See LICENSE for details.