1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

51 lines
1.0 KiB
TypeScript
Raw Normal View History

import {Request} from 'express';
export enum ErrorCodes {
2018-05-28 14:03:12 -04:00
NOT_AUTHENTICATED = 1,
ALREADY_AUTHENTICATED = 2,
NOT_AUTHORISED = 3,
PERMISSION_DENIED = 4,
CREDENTIAL_NOT_FOUND = 5,
2018-05-28 14:03:12 -04:00
USER_CREATION_ERROR = 6,
2018-05-28 14:03:12 -04:00
GENERAL_ERROR = 7,
THUMBNAIL_GENERATION_ERROR = 8,
2019-03-03 21:17:42 +01:00
PERSON_ERROR = 9,
SERVER_ERROR = 10,
2016-07-07 12:26:36 +02:00
2019-03-03 21:17:42 +01:00
USER_MANAGEMENT_DISABLED = 11,
2017-07-03 19:17:49 +02:00
2019-03-03 21:17:42 +01:00
INPUT_ERROR = 12,
2016-05-09 17:04:56 +02:00
2019-07-27 22:56:12 +02:00
SETTINGS_ERROR = 13,
2019-12-24 12:22:25 +01:00
TASK_ERROR = 14,
2021-04-06 11:32:31 +02:00
JOB_ERROR = 15,
LocationLookUp_ERROR = 16,
ALBUM_ERROR = 17,
}
2017-07-15 12:47:11 +02:00
export class ErrorDTO {
2019-12-10 14:50:20 +01:00
public detailsStr: string;
public request: {
method: string, url: string
} = {method: '', url: ''};
2019-12-10 14:50:20 +01:00
constructor(public code: ErrorCodes, public message?: string, public details?: any, req?: Request) {
2020-01-07 22:17:54 +01:00
this.detailsStr = (this.details ? this.details.toString() : '') || ErrorCodes[code];
2020-12-27 22:32:26 +01:00
if (req) {
this.request = {
method: req.method,
url: req.url
};
}
}
2019-01-26 18:03:40 -05:00
toString(): string {
2019-12-10 14:50:20 +01:00
return '[' + ErrorCodes[this.code] + '] ' + this.message + this.detailsStr;
2019-01-26 18:03:40 -05:00
}
}