replace typed errors with custom errors
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
import typedError from 'error/typed';
|
||||
export function WorkerTimeoutError(message, props = {}) {
|
||||
this.name = 'WorkerTimeoutError';
|
||||
this.message = message;
|
||||
this.timeout = props.timeout;
|
||||
this.jobId = props.jobId;
|
||||
|
||||
const errors = {};
|
||||
if ("captureStackTrace" in Error) Error.captureStackTrace(this, WorkerTimeoutError);
|
||||
else this.stack = (new Error()).stack;
|
||||
}
|
||||
WorkerTimeoutError.prototype = Object.create(Error.prototype);
|
||||
|
||||
errors.WorkerTimeoutError = typedError({
|
||||
type: 'WorkerTimeoutError',
|
||||
message: 'worker timed out, timeout={timeout}',
|
||||
timeout: null,
|
||||
jobId: null
|
||||
});
|
||||
export function UnspecifiedWorkerError(message, props = {}) {
|
||||
this.name = 'UnspecifiedWorkerError';
|
||||
this.message = message;
|
||||
this.jobId = props.jobId;
|
||||
|
||||
errors.UnspecifiedWorkerError = typedError({
|
||||
type: 'UnspecifiedWorkerError',
|
||||
message: 'Unspecified worker error',
|
||||
timeout: null,
|
||||
jobId: null
|
||||
});
|
||||
|
||||
export default errors;
|
||||
if ("captureStackTrace" in Error) Error.captureStackTrace(this, UnspecifiedWorkerError);
|
||||
else this.stack = (new Error()).stack;
|
||||
}
|
||||
UnspecifiedWorkerError.prototype = Object.create(Error.prototype);
|
||||
|
||||
51
test/src/helpers/errors.js
Normal file
51
test/src/helpers/errors.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import expect from 'expect.js';
|
||||
import { WorkerTimeoutError, UnspecifiedWorkerError } from '../../../lib/helpers/errors';
|
||||
|
||||
describe('custom errors', function () {
|
||||
describe('WorkerTimeoutError', function () {
|
||||
it('should be function', () => {
|
||||
expect(WorkerTimeoutError).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should have a name', function () {
|
||||
const err = new WorkerTimeoutError('timeout error');
|
||||
expect(err).to.have.property('name', 'WorkerTimeoutError');
|
||||
});
|
||||
|
||||
it('should take a jobId property', function () {
|
||||
const err = new WorkerTimeoutError('timeout error', { jobId: 'il7hl34rqlo8ro' });
|
||||
expect(err).to.have.property('jobId', 'il7hl34rqlo8ro');
|
||||
});
|
||||
|
||||
it('should take a timeout property', function () {
|
||||
const err = new WorkerTimeoutError('timeout error', { timeout: 15000 });
|
||||
expect(err).to.have.property('timeout', 15000);
|
||||
});
|
||||
|
||||
it('should be stringifyable', function () {
|
||||
const err = new WorkerTimeoutError('timeout error');
|
||||
expect(`${err}`).to.equal('WorkerTimeoutError: timeout error');
|
||||
});
|
||||
});
|
||||
|
||||
describe('UnspecifiedWorkerError', function () {
|
||||
it('should be function', () => {
|
||||
expect(UnspecifiedWorkerError).to.be.a('function');
|
||||
});
|
||||
|
||||
it('should have a name', function () {
|
||||
const err = new UnspecifiedWorkerError('unspecified error');
|
||||
expect(err).to.have.property('name', 'UnspecifiedWorkerError');
|
||||
});
|
||||
|
||||
it('should take a jobId property', function () {
|
||||
const err = new UnspecifiedWorkerError('unspecified error', { jobId: 'il7hl34rqlo8ro' });
|
||||
expect(err).to.have.property('jobId', 'il7hl34rqlo8ro');
|
||||
});
|
||||
|
||||
it('should be stringifyable', function () {
|
||||
const err = new UnspecifiedWorkerError('unspecified error');
|
||||
expect(`${err}`).to.equal('UnspecifiedWorkerError: unspecified error');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user