mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
fix: Add name in errors
This commit is contained in:
parent
f29157fb8f
commit
b769cd0b4a
@ -537,7 +537,7 @@ module.exports = class Database extends Observable {
|
||||
, 'Read Only': 'text'
|
||||
, 'File': 'text'
|
||||
, 'Attach': 'text'
|
||||
, 'Attach Image': 'text'
|
||||
, 'AttachImage': 'text'
|
||||
, 'Signature': 'text'
|
||||
, 'Color': 'text'
|
||||
, 'Barcode': 'text'
|
||||
|
@ -237,7 +237,8 @@ module.exports = class sqliteDatabase extends Database {
|
||||
this.conn.run(query, params, (err) => {
|
||||
if (err) {
|
||||
console.error('Error in sql:', query);
|
||||
reject(err);
|
||||
let Error = this.getError(err.errno);
|
||||
reject(new Error());
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@ -291,11 +292,17 @@ module.exports = class sqliteDatabase extends Database {
|
||||
, 'Read Only': 'text'
|
||||
, 'File': 'text'
|
||||
, 'Attach': 'text'
|
||||
, 'Attach Image': 'text'
|
||||
, 'AttachImage': 'text'
|
||||
, 'Signature': 'text'
|
||||
, 'Color': 'text'
|
||||
, 'Barcode': 'text'
|
||||
, 'Geolocation': 'text'
|
||||
}
|
||||
}
|
||||
|
||||
getError(errCode) {
|
||||
return {
|
||||
19: frappe.errors.DuplicateEntryError
|
||||
}[errCode] || Error;
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,52 @@
|
||||
const frappe = require('frappejs');
|
||||
|
||||
class BaseError extends Error {
|
||||
constructor(statusCode, ...params) {
|
||||
super(...params);
|
||||
constructor(statusCode, message) {
|
||||
super(message);
|
||||
this.name = 'BaseError';
|
||||
this.statusCode = statusCode;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
class ValidationError extends BaseError {
|
||||
constructor(...params) {
|
||||
super(417, ...params);
|
||||
constructor(message) {
|
||||
super(417, message);
|
||||
this.name = 'ValidationError';
|
||||
}
|
||||
}
|
||||
|
||||
class NotFound extends BaseError {
|
||||
constructor(...params) {
|
||||
super(404, ...params);
|
||||
class NotFoundError extends BaseError {
|
||||
constructor(message) {
|
||||
super(404, message);
|
||||
this.name = 'NotFoundError';
|
||||
}
|
||||
}
|
||||
|
||||
class Forbidden extends BaseError {
|
||||
constructor(...params) {
|
||||
super(403, ...params);
|
||||
class ForbiddenError extends BaseError {
|
||||
constructor(message) {
|
||||
super(403, message);
|
||||
this.name = 'ForbiddenError';
|
||||
}
|
||||
}
|
||||
|
||||
class ValueError extends ValidationError { }
|
||||
class Conflict extends ValidationError { }
|
||||
class DuplicateEntryError extends ValidationError {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.name = 'DuplicateEntryError';
|
||||
}
|
||||
}
|
||||
|
||||
function throwError(message, error='ValidationError') {
|
||||
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
|
||||
ValidationError: ValidationError,
|
||||
NotFoundError: NotFoundError,
|
||||
ForbiddenError: ForbiddenError,
|
||||
ValueError: ValueError,
|
||||
Conflict: Conflict
|
||||
};
|
||||
const err = new errorClass[error](message);
|
||||
frappe.events.trigger('throw', { message, stackTrace: err.stack });
|
||||
@ -47,7 +59,8 @@ module.exports = {
|
||||
ValidationError,
|
||||
ValueError,
|
||||
Conflict,
|
||||
NotFound,
|
||||
Forbidden,
|
||||
NotFoundError,
|
||||
ForbiddenError,
|
||||
DuplicateEntryError,
|
||||
throw: throwError
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user