Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 13x 13x 13x 13x 13x 13x 8x 13x 13x | /**
* This is the base class for custom errors in
* the application.
*/
export class ApplicationError extends Error {
constructor(message, extra = {}) {
super();
Eif (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = 'ApplicationError';
this.message = message;
this.code = extra.code;
}
}
/**
* Create a new custom error class e.g.
* const UserNotFoundError = createApplicationErrorClass('UserNotFoundError');
*
* // Later
* throw new UserNotFoundError(`user ${user.name} not found`);
*
*/
export default function createApplicationErrorClass(name) {
return class extends ApplicationError {
constructor(...params) {
super(...params);
this.name = name;
}
};
}
|