Errors handling

Node.js v13.5+ new argument params help you trace warnings and errors

  • --trace-uncaught

  • --trace-warnings

Example, node --trace-uncaught server.js

Error handling

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

GET http://localhost:8000/anyUrl

Path Parameters

Name
Type
Description

string

Validation error handler

GET http://locahost:8000/validate-error

Request Body

Name
Type
Description

foo

string

bar

Last updated

Was this helpful?