mirror of
https://github.com/zoriya/flood.git
synced 2026-06-09 21:10:03 +00:00
server: catch unhandled rejections and exceptions in production
This commit is contained in:
+21
-1
@@ -5,7 +5,27 @@ import chalk from 'chalk';
|
||||
import enforcePrerequisites from './enforce-prerequisites';
|
||||
import migrateData from './migrations/run';
|
||||
|
||||
process.env.NODE_ENV = process.env.NODE_ENV !== 'development' ? 'production' : 'development';
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
// Use production mode by default
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
// Catch unhandled rejections and exceptions
|
||||
// Traces are pretty useless with minimized production codes
|
||||
// This avoids printing a large section of junk
|
||||
const message = 'FATAL internal error. Please open an issue.';
|
||||
|
||||
process.on('unhandledRejection', (reason) => {
|
||||
console.error(message);
|
||||
console.error(`Unhandled rejection: ${(reason as Error)?.message ?? reason}`);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
console.error(message);
|
||||
console.error(`Uncaught exception: ${error.name}: ${error.message}`);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
||||
enforcePrerequisites()
|
||||
.then(migrateData)
|
||||
|
||||
Reference in New Issue
Block a user