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({
|
export function UnspecifiedWorkerError(message, props = {}) {
|
||||||
type: 'WorkerTimeoutError',
|
this.name = 'UnspecifiedWorkerError';
|
||||||
message: 'worker timed out, timeout={timeout}',
|
this.message = message;
|
||||||
timeout: null,
|
this.jobId = props.jobId;
|
||||||
jobId: null
|
|
||||||
});
|
|
||||||
|
|
||||||
errors.UnspecifiedWorkerError = typedError({
|
if ("captureStackTrace" in Error) Error.captureStackTrace(this, UnspecifiedWorkerError);
|
||||||
type: 'UnspecifiedWorkerError',
|
else this.stack = (new Error()).stack;
|
||||||
message: 'Unspecified worker error',
|
}
|
||||||
timeout: null,
|
UnspecifiedWorkerError.prototype = Object.create(Error.prototype);
|
||||||
jobId: null
|
|
||||||
});
|
|
||||||
|
|
||||||
export default errors;
|
|
||||||
|
|||||||
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