diff --git a/batch/job_backend.js b/batch/job_backend.js index 4a187695..cfa29893 100644 --- a/batch/job_backend.js +++ b/batch/job_backend.js @@ -61,7 +61,17 @@ function isJobFound(redisValues) { return !!(redisValues[0] && redisValues[1] && redisValues[2] && redisValues[3] && redisValues[4]); } +function getNotFoundError(job_id) { + var notFoundError = new Error('Job with id ' + job_id + ' not found'); + notFoundError.name = 'NotFoundError'; + return notFoundError; +} + JobBackend.prototype.get = function (job_id, callback) { + if (!job_id) { + return callback(getNotFoundError(job_id)) + } + var self = this; var redisParams = [ REDIS_PREFIX + job_id, @@ -81,9 +91,7 @@ JobBackend.prototype.get = function (job_id, callback) { } if (!isJobFound(redisValues)) { - var notFoundError = new Error('Job with id ' + job_id + ' not found'); - notFoundError.name = 'NotFoundError'; - return callback(notFoundError); + return callback(getNotFoundError(job_id)); } var jobData = toObject(job_id, redisParams, redisValues); diff --git a/test/integration/batch/job_backend.test.js b/test/integration/batch/job_backend.test.js index 0482fd65..75088e14 100644 --- a/test/integration/batch/job_backend.test.js +++ b/test/integration/batch/job_backend.test.js @@ -58,7 +58,7 @@ describe('job backend', function() { delete job.data.job_id; - jobBackend.create(job, function (err) { + jobBackend.create(job.data, function (err) { assert.ok(err); assert.equal(err.name, 'NotFoundError'); assert.equal(err.message, 'Job with id undefined not found');