57 lines
1.3 KiB
JavaScript
Raw Normal View History

2021-05-10 15:36:09 +02:00
'use strict';
2021-10-20 17:30:05 +02:00
/* DatabaseError */
class DatabaseError extends Error {
constructor(message, details = {}) {
super();
this.name = 'DatabaseError';
this.message = message || 'A database error occured';
this.details = details;
}
}
class NotNullConstraint extends DatabaseError {
2021-06-24 18:28:36 +02:00
constructor({ column = '' } = {}) {
super();
this.name = 'NotNullConstraint';
2021-10-20 17:30:05 +02:00
this.message = `Not null constraint violation${column ? ` on column ${column}` : ''}.`;
this.details = { column };
2021-07-29 16:39:26 +02:00
this.stack = '';
2021-05-10 15:36:09 +02:00
}
}
2021-10-20 17:30:05 +02:00
class InvalidTimeError extends DatabaseError {
constructor(message) {
super();
this.name = 'InvalidTimeFormat';
this.message = message || 'Invalid time format, expected HH:mm:ss.SSS';
this.details = {};
}
}
class InvalidDateError extends DatabaseError {
constructor(message) {
super();
this.name = 'InvalidTimeFormat';
this.message = message || 'Invalid date format, expected YYYY-MM-DD';
this.details = {};
}
}
class InvalidDateTimeError extends DatabaseError {
constructor(message) {
super();
this.name = 'InvalidTimeFormat';
this.message = message || 'Invalid datetime format, expected a timestamp or an ISO date';
this.details = {};
}
}
2021-05-10 15:36:09 +02:00
module.exports = {
2021-10-20 17:30:05 +02:00
DatabaseError,
2021-06-24 18:28:36 +02:00
NotNullConstraint,
2021-10-20 17:30:05 +02:00
InvalidTimeError,
InvalidDateError,
InvalidDateTimeError,
2021-05-10 15:36:09 +02:00
};