Files
stocca-tre/server/Result.ts
2022-07-10 23:07:51 +02:00

36 lines
981 B
TypeScript

export class StoccaTreError {
public message: string;
private statusCode: number = 500;
constructor(message: string, status: number = 500) {
this.message = message;
this.statusCode = 500;
this.status = status;
}
qualified(qualification: string): this {
const insertionPoint = qualification.indexOf("$err");
this.message = insertionPoint !== -1
? `${qualification.slice(0, insertionPoint)}${this.message}${qualification.slice(insertionPoint + 4)}`
: `${qualification}${this.message}`;
return this;
}
get status(): number {
return this.statusCode;
}
set status(code: number) {
if (code >= 100 && code < 600) {
this.statusCode = code;
}
}
withStatus(code: number): this {
this.status = code;
return this;
}
}
export type Result<T> = [error: undefined, just: T] | [error: StoccaTreError, just?: undefined];