2022-05-03 15:13:55 +00:00
|
|
|
import { t } from './translation';
|
|
|
|
|
2022-03-21 05:47:26 +00:00
|
|
|
export class BaseError extends Error {
|
2022-05-03 15:13:55 +00:00
|
|
|
label: string;
|
2022-03-21 05:47:26 +00:00
|
|
|
message: string;
|
|
|
|
statusCode: number;
|
|
|
|
|
|
|
|
constructor(statusCode: number, message: string) {
|
|
|
|
super(message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Base Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'BaseError';
|
|
|
|
this.statusCode = statusCode;
|
|
|
|
this.message = message;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ValidationError extends BaseError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(417, message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Validation Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'ValidationError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class NotFoundError extends BaseError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(404, message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Not Found Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'NotFoundError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ForbiddenError extends BaseError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(403, message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Forbidden Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'ForbiddenError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DuplicateEntryError extends ValidationError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Duplicate Entry Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'DuplicateEntryError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class LinkValidationError extends ValidationError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Link Validation Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'LinkValidationError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class MandatoryError extends ValidationError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Mandatory Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'MandatoryError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class DatabaseError extends BaseError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(500, message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Database Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'DatabaseError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CannotCommitError extends DatabaseError {
|
|
|
|
constructor(message: string) {
|
|
|
|
super(message);
|
2022-05-03 15:13:55 +00:00
|
|
|
this.label = t`Cannot Commit Error`;
|
2022-03-21 05:47:26 +00:00
|
|
|
this.name = 'CannotCommitError';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class ValueError extends ValidationError {}
|
2022-04-25 06:33:31 +00:00
|
|
|
export class ConflictError extends ValidationError {}
|
2022-03-21 05:47:26 +00:00
|
|
|
export class InvalidFieldError extends ValidationError {}
|