Added a better error handling

This commit is contained in:
2025-12-20 15:48:57 +01:00
parent f6f4a249c1
commit 18efd445e5
4 changed files with 51 additions and 16 deletions

View File

@@ -96,6 +96,21 @@ for (const route of routes) {
}
}
app.use((err, req, res, next) => {
const statusCode = err.statusCode || 500
logger.error(err.message, ["API", "red"])
if (typeof err.serialize === "function") {
return res.status(statusCode).json(err.serialize())
}
return res.status(500).json({
status: "error",
message: "Internal Server Error"
})
})
app.listen(process.env.WEB_PORT || 3000, () => {
logger.log(`Server listening at port : ${process.env.WEB_PORT || 3000}`, ["WEB", "yellow"])
})