mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Improved error handling
This commit is contained in:
parent
0ac0065753
commit
897fe6c63e
2 changed files with 6 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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) ->
|
||||
|
|
Loading…
Reference in a new issue