Errors handling
Error handling
Only async route functions and middlewares are handled
app.setErrorHandler(
(err: Error, req: HttpRequest, res: HttpResponse): HttpResponse => {
if (checkSomething(err)) {
return res.send({
status: 'error',
status_code: 500,
message: 'oops'
})
}
}
);
GET
http://localhost:8000/error-route
Path Parameters
Name
Type
Description
string
Not found handler
app.setNotFoundHandler((req: HttpRequest, res: HttpResponse): HttpResponse => {
return res.send({ code: 404, message: 'You entered wrong url' });
});
GET
http://localhost:8000/anyUrl
Path Parameters
Name
Type
Description
string
Validation error handler
Validation error handler unavailable for pro-slim version
app.setValidationErrorHandler((errors: AjvValidationErrors[], req: HttpRequest, res: HttpResponse): HttpResponse => {
return res.json({ errors });
});
GET
http://locahost:8000/validate-error
Request Body
Name
Type
Description
foo
string
bar
{
"errors": {
"type": "errors",
"errors": [
{
"body": ["type should be string, but got ..."]
}
]
}
}
Last updated
Was this helpful?