Skip to content

Commit

Permalink
Create errorHandling.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Oct 31, 2024
1 parent ef0254d commit 78e4655
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions blockchain_integration/pi_network/middleware/errorHandling.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// middleware/errorHandling.js

const errorHandlingMiddleware = (err, req, res, next) => {
console.error(err.stack); // Log the error stack for debugging

const statusCode = err.statusCode || 500; // Default to 500 if no status code is set
const message = err.message || 'Internal Server Error';

res.status(statusCode).json({
status: 'error',
statusCode,
message,
});
};

module.exports = errorHandlingMiddleware;

0 comments on commit 78e4655

Please sign in to comment.