2019-01-02 01:00:53 +01:00
|
|
|
export type TStatusGroup = 'clientError' | 'serverError';
|
2017-04-06 17:00:38 +02:00
|
|
|
|
|
|
|
export class HttpStatus {
|
2021-08-16 15:36:41 +02:00
|
|
|
public static statusMap: { [key: string]: any } = {};
|
|
|
|
public static addStatus(statusStringArg: string, statusArg: any) {
|
2019-01-02 02:08:12 +01:00
|
|
|
HttpStatus.statusMap[statusStringArg] = statusArg;
|
|
|
|
}
|
2021-08-16 15:36:41 +02:00
|
|
|
public static getHttpStatusByString(codeStringArg: string): HttpStatus {
|
2021-08-19 18:40:04 +02:00
|
|
|
let statusInstance: HttpStatus;
|
|
|
|
try {
|
|
|
|
statusInstance = new HttpStatus.statusMap[codeStringArg]();
|
|
|
|
} catch {
|
2024-12-25 14:23:42 +01:00
|
|
|
console.log('unknown status');
|
2021-08-19 18:42:52 +02:00
|
|
|
return new HttpStatus({
|
|
|
|
code: 0,
|
|
|
|
text: 'unknown status',
|
2024-12-25 14:23:42 +01:00
|
|
|
description: `The status ${codeStringArg} is not known.`,
|
2021-08-19 18:42:52 +02:00
|
|
|
});
|
2021-08-19 18:40:04 +02:00
|
|
|
}
|
2019-01-02 02:08:12 +01:00
|
|
|
return statusInstance;
|
2019-01-02 01:00:53 +01:00
|
|
|
}
|
2019-01-02 01:29:35 +01:00
|
|
|
public code: number;
|
|
|
|
public text: string;
|
|
|
|
public description: string;
|
2019-01-02 01:00:53 +01:00
|
|
|
constructor(optionsArg: { code: number; text: string; description: string }) {
|
|
|
|
this.code = optionsArg.code;
|
|
|
|
this.text = optionsArg.text;
|
|
|
|
this.description = optionsArg.description;
|
2017-04-06 17:00:38 +02:00
|
|
|
}
|
|
|
|
}
|