Improved error handling

This commit is contained in:
Michael Schmatz 2014-11-28 11:44:03 -05:00
parent 0ac0065753
commit 897fe6c63e
2 changed files with 6 additions and 4 deletions

View file

@ -2,6 +2,7 @@ log = require 'winston'
errors = require '../commons/errors'
handlers = require('../commons/mapping').handlers
mongoose = require 'mongoose'
hipchat = require '../hipchat'
module.exports.setup = (app) ->
# This is hacky and should probably get moved somewhere else, I dunno
@ -41,10 +42,12 @@ module.exports.setup = (app) ->
return handler.patch(req, res, parts[1]) if req.route.method is 'patch' and parts[1]?
handler[req.route.method](req, res, parts[1..]...)
catch error
log.error("Error trying db method #{req.route.method} route #{parts} from #{name}: #{error}")
errorMessage = "Error trying db method #{req?.route?.method} route #{parts} from #{name}: #{error}"
log.error(errorMessage)
log.error(error)
log.error(error.stack)
errors.notFound(res, "Route #{req.path} not found.")
hipchat.sendTowerHipChatMessage errorMessage
errors.notFound(res, "Route #{req?.path} not found.")
getSchema = (req, res, moduleName) ->
try

View file

@ -43,8 +43,7 @@ setupErrorMiddleware = (app) ->
app.use (err, req, res, next) ->
if err
res.status(500).send(error: "Something went wrong!")
hipchat.sendTowerHipChatMessage("The server crashed. Stack trace: <br> <code>#{err.stack}</code>")
console.log "Got a server error: #{err.stack}"
hipchat.sendTowerHipChatMessage("The server crashed. Path: #{req.path}, Stack trace: <br> <code>#{err.stack}</code>")
else
next(err)
setupExpressMiddleware = (app) ->