Files

104 lines
2.6 KiB
JavaScript
Raw Permalink Normal View History

2025-09-02 21:43:00 +10:00
import _ from "lodash";
2020-02-19 15:55:06 +11:00
2025-09-02 21:43:00 +10:00
const errs = {
PermissionError: function (_, previous) {
2020-02-19 15:55:06 +11:00
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = "Permission Denied";
this.public = true;
this.status = 403;
2020-02-19 15:55:06 +11:00
},
ItemNotFoundError: function (id, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
this.message = "Not Found";
if (id) {
this.message = `Not Found - ${id}`;
}
2025-09-02 21:43:00 +10:00
this.public = true;
this.status = 404;
2020-02-19 15:55:06 +11:00
},
2025-09-02 21:43:00 +10:00
AuthError: function (message, messageI18n, previous) {
2020-02-19 15:55:06 +11:00
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.message_i18n = messageI18n;
this.public = true;
this.status = 400;
2020-02-19 15:55:06 +11:00
},
InternalError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.status = 500;
this.public = false;
2020-02-19 15:55:06 +11:00
},
InternalValidationError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.status = 400;
this.public = false;
2020-02-19 15:55:06 +11:00
},
ConfigurationError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.status = 400;
this.public = true;
2020-02-19 15:55:06 +11:00
},
CacheError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
this.message = message;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.status = 500;
this.public = false;
2020-02-19 15:55:06 +11:00
},
ValidationError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.public = true;
this.status = 400;
2020-02-19 15:55:06 +11:00
},
AssertionFailedError: function (message, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2020-02-19 15:55:06 +11:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = message;
this.public = false;
this.status = 400;
2024-01-18 12:26:55 +10:00
},
CommandError: function (stdErr, code, previous) {
Error.captureStackTrace(this, this.constructor);
2025-09-02 21:43:00 +10:00
this.name = this.constructor.name;
2024-01-18 12:26:55 +10:00
this.previous = previous;
2025-09-02 21:43:00 +10:00
this.message = stdErr;
this.code = code;
this.public = false;
2024-01-18 12:26:55 +10:00
},
2020-02-19 15:55:06 +11:00
};
2025-09-02 21:43:00 +10:00
_.forEach(errs, (err) => {
err.prototype = Object.create(Error.prototype);
2020-02-19 15:55:06 +11:00
});
2025-09-02 21:43:00 +10:00
export default errs;