mirror of
https://github.com/frappe/books.git
synced 2024-12-26 20:30:25 +00:00
b96ea40b99
* Add error modal * Initialize frappe.error and frappe.events. Code formatting * Fix indentation
54 lines
1.1 KiB
JavaScript
54 lines
1.1 KiB
JavaScript
const frappe = require('frappejs');
|
|
|
|
class BaseError extends Error {
|
|
constructor(statusCode, ...params) {
|
|
super(...params);
|
|
this.statusCode = statusCode;
|
|
}
|
|
}
|
|
|
|
class ValidationError extends BaseError {
|
|
constructor(...params) {
|
|
super(417, ...params);
|
|
}
|
|
}
|
|
|
|
class NotFound extends BaseError {
|
|
constructor(...params) {
|
|
super(404, ...params);
|
|
}
|
|
}
|
|
|
|
class Forbidden extends BaseError {
|
|
constructor(...params) {
|
|
super(403, ...params);
|
|
}
|
|
}
|
|
|
|
class ValueError extends ValidationError { }
|
|
class Conflict extends ValidationError { }
|
|
|
|
function throwError(message, error='ValidationError') {
|
|
const errorClass = {
|
|
'ValidationError': ValidationError,
|
|
'NotFound': NotFound,
|
|
'Forbidden': Forbidden,
|
|
'ValueError': ValueError,
|
|
'Conflict': Conflict
|
|
};
|
|
const err = new errorClass[error](message);
|
|
frappe.events.trigger('throw', { message, stackTrace: err.stack });
|
|
throw err;
|
|
}
|
|
|
|
frappe.throw = throwError;
|
|
|
|
module.exports = {
|
|
ValidationError,
|
|
ValueError,
|
|
Conflict,
|
|
NotFound,
|
|
Forbidden,
|
|
throw: throwError
|
|
}
|