Make a clear distinction between programmer errors ("internal errors") and runtime errors, and allow configuring the server to let the programmer errors bubble up in development and unit testing. This saves a huge amount of time because it generates ordinary stack traces when things go wrong. And, if these errors occur in production, we'll catch them, and display **shields | internal error** which is the equivalent of a 500 error.
40 lines
997 B
JavaScript
40 lines
997 B
JavaScript
'use strict';
|
|
|
|
class NotFound extends Error {
|
|
constructor(prettyMessage = 'not found') {
|
|
const message = prettyMessage === 'not found'
|
|
? 'Not Found'
|
|
: `Not Found: ${prettyMessage}`;
|
|
super(message);
|
|
this.prettyMessage = prettyMessage;
|
|
this.name = 'NotFound';
|
|
}
|
|
}
|
|
|
|
class InvalidResponse extends Error {
|
|
constructor(prettyMessage = 'invalid', underlyingError) {
|
|
const message = underlyingError
|
|
? `Invalid Response: ${underlyingError.message}`
|
|
: 'Invalid Response';
|
|
super(message);
|
|
this.stack = underlyingError.stack;
|
|
this.prettyMessage = prettyMessage;
|
|
this.name = 'InvalidResponse';
|
|
}
|
|
}
|
|
|
|
class Inaccessible extends Error {
|
|
constructor(underlyingError, prettyMessage = 'inaccessible') {
|
|
super(`Inaccessible: ${underlyingError.message}`);
|
|
this.stack = underlyingError.stack;
|
|
this.prettyMessage = prettyMessage;
|
|
this.name = 'Inaccessible';
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
NotFound,
|
|
InvalidResponse,
|
|
Inaccessible,
|
|
};
|