fix: log all unhandled errors inside next handlers, terminate app properly for unhandled error outside
This commit is contained in:
parent
d259587491
commit
646e75d5f8
1 changed files with 8 additions and 0 deletions
|
|
@ -32,6 +32,7 @@ const logger = winston.createLogger({
|
|||
|
||||
process.on('uncaughtException', (error: Error) => {
|
||||
logger.error(`Uncaught exception caught: ${error}, cause: ${error.cause}, stack: ${error.stack}`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (error: Error) => {
|
||||
|
|
@ -78,6 +79,13 @@ addon.use('/', (new ManifestController(sources, extractors)).router);
|
|||
const streamResolver = new StreamResolver(logger, extractorRegistry);
|
||||
addon.use('/', (new StreamController(logger, sources, streamResolver)).router);
|
||||
|
||||
// error handler needs to stay at the end of the stack
|
||||
addon.use((err: Error, _req: Request, _res: Response, next: NextFunction) => {
|
||||
logger.error(`Error: ${err}, cause: ${err.cause}, stack: ${err.stack}`);
|
||||
|
||||
return next(err);
|
||||
});
|
||||
|
||||
addon.get('/', (_req: Request, res: Response) => {
|
||||
res.redirect('/configure');
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue