Handle http errors in an easy way
npm install http-errors-wrapperThis module allows you to throw custom and specific http-errors when handling server responses in your NodeJS APIs.





The minimum supported version of Node.js is v10.
``bash`
$ npm i http-errors-wrapper
Run from the root folder:
`bash`
$ npm run test
`js`
const HttpErrors = require('http-errors-wrapper');
`js
const HttpErrors = require('http-errors-wrapper');
try {
throw new HttpErrors.notFoundError('User not found');
} catch (error) {
if (error.isHttpError) {
const { statusCode, message } = error;
return res.status(statusCode).send({ statusCode, message });
}
}
`
Each http error from this module has:
- date: Date when the error where thrown with format YYYY-MM-DD HH:mm:ssisHttpError
- : Flag to indicate the error belongs to this module in order to handle itmessage
- : Custom message to send with the error. A short description to resume what happened. By default is the error name provided by MDN Web Docsname
- : The default http error namestatusCode
- : The default http status codestack
- : Error stack trace where was thrown
- badRequestError: Handles 400 http errorunauthorizedError
- : Handles 401 http errorforbiddenError
- : Handles 403 http errornotFoundError
- : Handles 404 http errormethodNotAllowedError
- : Handles 405 http errorconflictError
- : Handles 409 http errorunsupportedMediaTypeError
- : Handles 415 http errorinternalServerError
- : Handles 500 http errorbadGatewayError
- : Handles 502 http errorThe rest will be added on demand`)
- (