Skip to content

Commit

Permalink
Optimize error
Browse files Browse the repository at this point in the history
  • Loading branch information
MD-ASHARUDDIN-90 committed Apr 30, 2024
1 parent ac9931e commit b55db3e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ app.delete("/delete", async (req, res) => {
//error handling
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something broke!");

const statusCode = err.statusCode ?? 500;
const errorMessage = err.message ?? "Internal Server Error";

res.status(statusCode).send(errorMessage);
});

//connect to database
Expand Down

0 comments on commit b55db3e

Please sign in to comment.