Lissy93/web-check

Missing Error Handling in Express Routes:

mrfelpa opened this issue · 1 comments

It is advisable to enclose the asynchronous segments of your code within a try...catch block in order to effectively manage and address any potential errors that may arise. I made an example:

test

Already is ;)

web-check/server.js

Lines 40 to 47 in 7559716

app.get(route, async (req, res) => {
try {
const { statusCode = 200, body = '' } = await executeHandler(handler, req);
res.status(statusCode).json(JSON.parse(body));
} catch (err) {
res.status(500).json({ error: err.message });
}
});