31 lines
975 B
TypeScript
31 lines
975 B
TypeScript
export type TStatusGroup = 'clientError' | 'serverError';
|
|
|
|
export class HttpStatus {
|
|
public static statusMap: { [key: string]: any } = {};
|
|
public static addStatus(statusStringArg: string, statusArg: any) {
|
|
HttpStatus.statusMap[statusStringArg] = statusArg;
|
|
}
|
|
public static getHttpStatusByString(codeStringArg: string): HttpStatus {
|
|
let statusInstance: HttpStatus;
|
|
try {
|
|
statusInstance = new HttpStatus.statusMap[codeStringArg]();
|
|
} catch {
|
|
console.log('unknown status');
|
|
return new HttpStatus({
|
|
code: 0,
|
|
text: 'unknown status',
|
|
description: `The status ${codeStringArg} is not known.`,
|
|
});
|
|
}
|
|
return statusInstance;
|
|
}
|
|
public code: number;
|
|
public text: string;
|
|
public description: string;
|
|
constructor(optionsArg: { code: number; text: string; description: string }) {
|
|
this.code = optionsArg.code;
|
|
this.text = optionsArg.text;
|
|
this.description = optionsArg.description;
|
|
}
|
|
}
|