backend-app-api: register global error handlers
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
---
|
||||
|
||||
Register unhandled rejection and uncaught exception handlers to avoid backend crashes.
|
||||
@@ -165,6 +165,25 @@ export class BackendInitializer {
|
||||
);
|
||||
await registerInit.init.func(deps);
|
||||
}
|
||||
|
||||
// Once the backend is started, any uncaught errors or unhandled rejections are caught
|
||||
// and logged, in order to avoid crashing the entire backend on local failures.
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
const rootLogger = await this.#serviceHolder.get(
|
||||
coreServices.rootLogger,
|
||||
'root',
|
||||
);
|
||||
process.on('unhandledRejection', (reason: Error) => {
|
||||
rootLogger
|
||||
?.child({ type: 'unhandledRejection' })
|
||||
?.error('Unhandled rejection', reason);
|
||||
});
|
||||
process.on('uncaughtException', error => {
|
||||
rootLogger
|
||||
?.child({ type: 'uncaughtException' })
|
||||
?.error('Uncaught exception', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#resolveInitOrder(registerInits: Array<BackendRegisterInit>) {
|
||||
|
||||
Reference in New Issue
Block a user