feat: things are happening...
This commit is contained in:
35
server/Result.ts
Normal file
35
server/Result.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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];
|
||||
Reference in New Issue
Block a user