From b02878d41da0075fcef20b0b8526f532f95052f6 Mon Sep 17 00:00:00 2001 From: Carlos Brito Lage Date: Sun, 20 Oct 2013 15:00:51 -0700 Subject: [PATCH] Added custom error handler --- server.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server.js b/server.js index 5dd5d32..1b4a912 100644 --- a/server.js +++ b/server.js @@ -82,6 +82,24 @@ app.get('/manifest.cache', function (req, res) { app.get('*', clientApp.html()); +app.use(function handleError(err, req, res, next) { + var errorResult = {message: 'something bad happened'}; + + if (config.isDev) { + if (err instanceof Error) { + if (err.message) { + errorResult.message = err.message; + } + + if (err.stack) { + errorResult.stack = err.stack; + } + } + } + + return res.send(500, errorResult); +}); + //https.createServer({ // key: fs.readFileSync(config.http.key), // cert: fs.readFileSync(config.http.cert)