Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit d2fbd55

Browse files
committed
fix: correct error handling middleware
1 parent f634dc6 commit d2fbd55

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/serve.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,16 @@ expressWs.app.post('/container-status', asyncHandler(async (req: express.Request
335335
).end()
336336
}))
337337

338-
// Error handling middleware
338+
// Error handling middleware which returns the error as JSON (the default returns HTML)
339339
app.use((error: Error, req: express.Request, res: express.Response, next: any) => {
340-
console.error(error.stack)
340+
// Send error to stderr
341+
console.error(error)
342+
// ... and as JSON to the client
341343
res.status(500)
342-
res.render('error', { error })
343-
next(error)
344+
res.json({
345+
error: error.message,
346+
trace: error.stack
347+
})
344348
})
345349

346350
/**

0 commit comments

Comments
 (0)