diff --git a/blockchain_integration/pi_network/middleware/errorHandling.js b/blockchain_integration/pi_network/middleware/errorHandling.js new file mode 100644 index 000000000..4da45cfc8 --- /dev/null +++ b/blockchain_integration/pi_network/middleware/errorHandling.js @@ -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;