Module responsible for encapsulating all http error requests and returns the correct exception.
const httpErrorsHandle = require('http-errors-handle');
const axios = require('axios');
var app = express();
app.use(async function (req, res, next) {
try {
const request = axios.get("http://example.test/");
const resp = await httpErrorsHandle(request);
next()
} catch (e) {
next(e)
//if it's a 400 error we'll have the following object:
/**
{
"message":"Bad Request",
"status":400,
"statusCode":400
}
**/
}
})
message
- the traditional error message, which should be kept short and all single linestatus
- the status code of the error, mirroringstatusCode
for general compatibilitystatusCode
- the status code of the error, defaulting to500
Create a new handle error object with the given message msg
.
The error object inherits from createError.HttpError
.
var resp = httpErrorsHandle(request, 'Ops!!! We have a error here...');
status: 500
- the status code as a numbermessage
- the message of the error, defaulting to node's text for that status code.
## License
[MIT]