fix task.challenge tests and add checks when scoring challenge tasks

This commit is contained in:
Matteo Pagliazzi
2016-05-25 14:49:08 +02:00
parent 506705d738
commit f713bf53c1
3 changed files with 5 additions and 3 deletions

View File

@@ -422,13 +422,15 @@ api.scoreTask = {
sendTaskWebhook(user.preferences.webhooks, _generateWebhookTaskData(task, direction, delta, userStats, user));
if (task.challenge.id && task.challenge.taskId && !task.challenge.broken && task.type !== 'reward') {
if (task.challenge && task.challenge.id && task.challenge.taskId && !task.challenge.broken && task.type !== 'reward') {
// Wrapping everything in a try/catch block because if an error occurs using `await` it MUST NOT bubble up because the request has already been handled
try {
let chalTask = await Tasks.Task.findOne({
_id: task.challenge.taskId,
}).exec();
if (!chalTask) return;
await chalTask.scoreChallengeTask(delta);
} catch (e) {
logger.error(e);