diff --git a/src/helpers/errors.js b/src/helpers/errors.js index 3fe368d..458d0f9 100644 --- a/src/helpers/errors.js +++ b/src/helpers/errors.js @@ -9,4 +9,11 @@ errors.WorkerTimeoutError = typedError({ jobId: null }); +errors.UnspecifiedWorkerError = typedError({ + type: 'UnspecifiedWorkerError', + message: 'Unspecified worker error', + timeout: null, + jobId: null +}); + export default errors; diff --git a/src/worker.js b/src/worker.js index 23c4b2e..c2f65f3 100644 --- a/src/worker.js +++ b/src/worker.js @@ -3,7 +3,7 @@ import Puid from 'puid'; import moment from 'moment'; import logger from './helpers/logger'; import constants from './helpers/constants'; -import { WorkerTimeoutError } from './helpers/errors'; +import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors'; const puid = new Puid(); const debug = logger('esqueue:worker'); @@ -173,6 +173,12 @@ export default class Job extends events.EventEmitter { this.emit('job_error', err); }); }, (jobErr) => { + if (!jobErr) { + jobErr = new UnspecifiedWorkerError({ + jobId: job._id, + }); + } + // job execution failed if (jobErr.type === 'WorkerTimeoutError') { this.debug(`Timeout on job ${job._id}`);