mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Added handler for unhandled rejections
refs https://github.com/TryGhost/Toolbox/issues/163 - as of Node 15, unhandled rejections will exit the process so if Ghost is running on Node 15+ and encounters one, it will kill Ghost - if Sentry is enabled, it will add a handler for the event that will send it to Sentry but the logging is sent to stdout/stderr, which means we lose it in Ghost logs - this commit adds a process handler for the `unhandledRejection` event which will log the reason to Ghost logs and prevent Ghost from exiting
This commit is contained in:
parent
32884fa412
commit
3ad871b21e
1 changed files with 7 additions and 0 deletions
|
@ -358,6 +358,13 @@ async function bootGhost({backend = true, frontend = true, server = true} = {})
|
||||||
debug('End: Load logging');
|
debug('End: Load logging');
|
||||||
|
|
||||||
// At this point logging is required, so we can handle errors better
|
// At this point logging is required, so we can handle errors better
|
||||||
|
|
||||||
|
// Add a process handler to capture and log unhandled rejections
|
||||||
|
debug('Begin: Add unhandled rejection handler');
|
||||||
|
process.on('unhandledRejection', (error) => {
|
||||||
|
logging.error('Unhandled rejection:', error);
|
||||||
|
});
|
||||||
|
debug('End: Add unhandled rejection handler');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error); // eslint-disable-line no-console
|
console.error(error); // eslint-disable-line no-console
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue