From d0be5c1f223d0bd26417ca042a2f826ceeb9cb2c Mon Sep 17 00:00:00 2001 From: Nick Winter Date: Sun, 8 May 2016 10:05:26 -0700 Subject: [PATCH] Handle a couple errors I saw in the logs --- .gitignore | 1 + server/models/Patch.coffee | 9 ++++++++- server/queues/scoring/scoringUtils.coffee | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 63213cf41..c4a59d9bf 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,4 @@ Dockerfile # coffeelint for editors (might be standardized eventually) coffeelint.json +gitSpy/* diff --git a/server/models/Patch.coffee b/server/models/Patch.coffee index 9aaabd981..d23c8dfe1 100644 --- a/server/models/Patch.coffee +++ b/server/models/Patch.coffee @@ -18,7 +18,14 @@ PatchSchema.pre 'save', (next) -> return next(err) collection = target.collection - handler = require('../' + handlers[collection]) + try + handler = require('../' + handlers[collection]) + catch err + console.error 'Couldn\'t find handler for collection:', target.collection, 'from target', target + err = new Error('Server error.') + err.response = {message: '', property: 'target.id'} + err.code = 500 + return next(err) handler.getDocumentForIdOrSlug targetID, (err, document) => if err err = new Error('Server error.') diff --git a/server/queues/scoring/scoringUtils.coffee b/server/queues/scoring/scoringUtils.coffee index 5eb2e52ec..2a8e0cd33 100644 --- a/server/queues/scoring/scoringUtils.coffee +++ b/server/queues/scoring/scoringUtils.coffee @@ -30,7 +30,7 @@ module.exports.sendResponseObject = (res, object) -> module.exports.formatSessionInformation = (session) -> heroID = if session.team is 'ogres' then 'hero-placeholder-1' else 'hero-placeholder' submittedCode = {} - submittedCode[heroID] = plan: LZString.compressToUTF16 session.submittedCode[heroID].plan + submittedCode[heroID] = plan: LZString.compressToUTF16(session.submittedCode[heroID]?.plan ? '') _id: session._id sessionID: session._id