Describe the bug
I've created custom Errors that implement HttpError interface from @map-colonies/error-express-handler.
For non-async routes, when error is being thrown, the middleware catches it and sends the right error and http code.
For async routes, when the same error is thrown, the server crash.
In order to solve this issue, I had to add Try-Catch for every async route. With this patch, I once again got the server to respond with the expected output (expected http code and message).
To Reproduce
Steps to reproduce the behavior:
- Create simple Express.JS server.
- Create custom error as described in the screenshots.
- Create routes as described in the screenshots.
- register
getErrorHandlerMiddleware() from @map-colonies/error-express-handler as post routes middleware. Example: app.use(getErrorHandlerMiddleware());
Expected behavior
I'd expect that the middleware will catch errors thrown at both async and non-async routes.
Screenshots
The custom error implementation:

Non-async route:

Postman response (as expected):

Async route that throws the same error:

Error:
/<Path>/ts-server-boilerplate/src/serverBuilder.ts:72
reject(new BadRequestError('temp route - bad request error'));
^
BadRequestError: temp route - bad request error
at <anonymous> (/<Path>/ts-server-boilerplate/src/serverBuilder.ts:72:16)
at new Promise (<anonymous>)
at <anonymous> (/<Path>/ts-server-boilerplate/src/serverBuilder.ts:71:13)
at <anonymous> (/<Path>/ts-server-boilerplate/node_modules/@opentelemetry/instrumentation-express/src/instrumentation.ts:223:27)
at Layer.handle [as handle_request] (/<Path>/ts-server-boilerplate/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/<Path>/ts-server-boilerplate/node_modules/express/lib/router/index.js:328:13)
at /<Path>/ts-server-boilerplate/node_modules/express/lib/router/index.js:286:9
at Function.process_params (/<Path>/ts-server-boilerplate/node_modules/express/lib/router/index.js:346:12)
at next (/<Path>/ts-server-boilerplate/node_modules/express/lib/router/index.js:280:10)
at traceContexHeaderMiddleware (/<Path>/ts-server-boilerplate/node_modules/@map-colonies/telemetry/src/tracing/middleware/traceOnHeaderMiddleware.ts:16:12) {
status: 400
}
Try-catch implementation:

Describe the bug
I've created custom Errors that implement
HttpErrorinterface from@map-colonies/error-express-handler.For non-async routes, when error is being thrown, the middleware catches it and sends the right error and http code.
For async routes, when the same error is thrown, the server crash.
In order to solve this issue, I had to add Try-Catch for every async route. With this patch, I once again got the server to respond with the expected output (expected http code and message).
To Reproduce
Steps to reproduce the behavior:
getErrorHandlerMiddleware()from@map-colonies/error-express-handleras post routes middleware. Example:app.use(getErrorHandlerMiddleware());Expected behavior
I'd expect that the middleware will catch errors thrown at both async and non-async routes.
Screenshots

The custom error implementation:
Non-async route:

Postman response (as expected):

Async route that throws the same error:

Error:
Try-catch implementation:
