mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Better error handling
This commit is contained in:
parent
16e264788a
commit
d56f594d58
4 changed files with 24 additions and 2 deletions
|
@ -5,7 +5,7 @@ if cluster.isMaster
|
|||
for i in [0...numCPUs]
|
||||
cluster.fork()
|
||||
cluster.on 'exit', (worker, code, signal) ->
|
||||
console.log 'worker' + worker.process.id + 'died'
|
||||
console.log 'worker ' + worker.id + ' died'
|
||||
cluster.fork()
|
||||
else
|
||||
require('coffee-script')
|
||||
|
|
|
@ -14,3 +14,15 @@ module.exports.sendHipChatMessage = sendHipChatMessage = (message) ->
|
|||
request.post {uri: url, json: form}, (err, res, body) ->
|
||||
return log.error 'Error sending HipChat patch request:', err or body if err or /error/i.test body
|
||||
#log.info "Got HipChat patch response:", body
|
||||
|
||||
module.exports.sendTowerHipChatMessage = sendTowerHipChatMessage = (message) ->
|
||||
return unless key = config.hipchatTowerAPIKey
|
||||
roomID = 318356
|
||||
form =
|
||||
color: 'red'
|
||||
notify: true
|
||||
message: message
|
||||
messageFormat: 'html'
|
||||
url = "https://api.hipchat.com/v2/room/#{roomID}/notification?auth_token=#{key}"
|
||||
request.post {uri: url, json: form}, (err, res, body) ->
|
||||
return log.error 'Error sending HipChat Tower message:', err or body if err or /error/i.test body
|
||||
|
|
|
@ -48,7 +48,7 @@ config.mail =
|
|||
cronHandlerPrivateIP: process.env.COCO_CRON_PRIVATE_IP or ''
|
||||
|
||||
config.hipchatAPIKey = process.env.COCO_HIPCHAT_API_KEY or ''
|
||||
|
||||
config.hipchatTowerAPIKey = process.env.COCO_HIPCHAT_TOWER_API_KEY or ''
|
||||
config.queue =
|
||||
accessKeyId: process.env.COCO_AWS_ACCESS_KEY_ID or ''
|
||||
secretAccessKey: process.env.COCO_AWS_SECRET_ACCESS_KEY or ''
|
||||
|
|
|
@ -13,6 +13,7 @@ logging = require './server/commons/logging'
|
|||
config = require './server_config'
|
||||
auth = require './server/routes/auth'
|
||||
UserHandler = require './server/users/user_handler'
|
||||
hipchat = require './server/hipchat'
|
||||
global.tv4 = require 'tv4' # required for TreemaUtils to work
|
||||
global.jsondiffpatch = require 'jsondiffpatch'
|
||||
|
||||
|
@ -38,6 +39,14 @@ developmentLogging = (tokens, req, res) ->
|
|||
elapsedColor = if elapsed < 500 then 90 else 31
|
||||
"\x1b[90m#{req.method} #{req.originalUrl} \x1b[#{color}m#{res.statusCode} \x1b[#{elapsedColor}m#{elapsed}ms\x1b[0m"
|
||||
|
||||
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}"
|
||||
else
|
||||
next(err)
|
||||
setupExpressMiddleware = (app) ->
|
||||
if config.isProduction
|
||||
express.logger.format('prod', productionLogging)
|
||||
|
@ -101,6 +110,7 @@ exports.setupMiddleware = (app) ->
|
|||
setupOneSecondDelayMiddleware app
|
||||
setupTrailingSlashRemovingMiddleware app
|
||||
setupRedirectMiddleware app
|
||||
setupErrorMiddleware app
|
||||
|
||||
###Routing function implementations###
|
||||
|
||||
|
|
Loading…
Reference in a new issue