Skip to content

Commit d78c8af

Browse files
authored
Merge pull request #3805 from Iron-56/security/error-handler
Unhandled exceptions disclosures potential sensitive information
2 parents d6a6c38 + 1d8d56d commit d78c8af

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

server/server.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,20 @@ app.get('*', async (req, res) => {
195195
res.type('txt').send('Not found.');
196196
});
197197

198+
// Global error handler for unhandled errors
199+
app.use((error, req, res, next) => {
200+
console.error('Unhandled error:', error);
201+
202+
if (res.headersSent) {
203+
return next(error);
204+
}
205+
206+
const statusCode = error.status || 500;
207+
return res.status(statusCode).json({
208+
error: 'Internal server error'
209+
});
210+
});
211+
198212
// start app
199213
app.listen(process.env.PORT, (error) => {
200214
if (!error) {

0 commit comments

Comments
 (0)