Is there any way to use custom middleware before the app use GlobalErrorHandlerMiddleware? I mean that this this middleware use
response.status(error.status).send(toHTML(error.message));
so any other middleware will not be running. So the question is how to use custom middleware before GlobalErrorHandlerMiddleware without overriding the orginal one? Or maybe there is any way to handle express response? I need handle response though the app send the error.
Hello @OskarLebuda
You can register you middleware on $afterRouteInit hook. If you take a look on this following url, you'll see the server lifecycle and his emitted hooks:
https://github.com/TypedProject/ts-express-decorators/blob/master/packages/common/src/server/components/ServerLoader.ts#L462-L477
See you :)
@Romakita right, I saw that, but have you any example how to register the middleware on any lifecycle hooks?
Ha yes :)
@Middleware()
class MyCustomMiddleware {
use(){}
}
class ServerLoader聽{
$afterRoutesInit() {
this.use(MyCustomMiddleware)
}
}
That's all i need :) Thx :)