trying some fixes for server crashing

This commit is contained in:
Tyler Renelle
2012-10-24 17:24:35 -04:00
parent bc460e5ecd
commit 9eb85a2782
4 changed files with 20 additions and 3 deletions

View File

@@ -175,6 +175,16 @@ score = function(taskId, direction, options) {
times: 1
};
}
if (_.isEmpty(model.get('_user'))) {
console.log({
taskId: taskId,
direction: direction,
options: options,
user: model.get('_user'),
error: 'non-user attempted to score'
});
return 0;
}
taskPath = "_user.tasks." + taskId;
_ref = [model.at(taskPath), model.get(taskPath)], task = _ref[0], taskObj = _ref[1];
type = taskObj.type, value = taskObj.value;

View File

@@ -1,8 +1,10 @@
// Generated by CoffeeScript 1.3.3
var scoring;
var scoring, _;
scoring = require('../app/scoring');
_ = require('lodash');
module.exports = function(expressApp, root, derby) {
var deprecatedMessage, staticPages;
staticPages = derby.createStatic(root);
@@ -34,7 +36,7 @@ module.exports = function(expressApp, root, derby) {
model.session.userId = uid;
return model.fetch("users." + uid, function(err, user) {
var delta, result;
if (err || !user.get()) {
if (err || _.isEmpty(user.get())) {
err || (err = 'No user with that ID');
return res.send(500, err);
}

View File

@@ -135,6 +135,10 @@ updateStats = (stats) ->
# {direction} 'up' or 'down'
# {options} will usually be passed in via cron or tests, safe to ignore this param
score = (taskId, direction, options={cron:false, times:1}) ->
# FIXME seem to be finding issues here
if _.isEmpty(model.get('_user'))
console.log {taskId:taskId, direction:direction, options:options, user:model.get('_user'), error: 'non-user attempted to score'}
return 0
taskPath = "_user.tasks.#{taskId}"
[task, taskObj] = [model.at(taskPath), model.get(taskPath)]
{type, value} = taskObj

View File

@@ -1,4 +1,5 @@
scoring = require('../app/scoring')
_ = require('lodash')
module.exports = (expressApp, root, derby) ->
@@ -29,7 +30,7 @@ module.exports = (expressApp, root, derby) ->
model = req.getModel()
model.session.userId = uid
model.fetch "users.#{uid}", (err, user) ->
if err || !user.get()
if err || _.isEmpty(user.get())
err ||= 'No user with that ID'
return res.send(500, err)
model.ref('_user', user)