From 47904011de646b92b1f3774f9a30bcfa118c5dc4 Mon Sep 17 00:00:00 2001 From: Dhravya Shah Date: Mon, 20 Jan 2025 17:49:19 -0700 Subject: =?UTF-8?q?Supermemory=20v2=20Release=20=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/errors/baseError.ts | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 apps/backend/src/errors/baseError.ts (limited to 'apps/backend/src/errors/baseError.ts') diff --git a/apps/backend/src/errors/baseError.ts b/apps/backend/src/errors/baseError.ts new file mode 100644 index 00000000..bccc54df --- /dev/null +++ b/apps/backend/src/errors/baseError.ts @@ -0,0 +1,45 @@ +export class BaseHttpError extends Error { + public status: number; + public message: string; + + constructor(status: number, message: string) { + super(message); + this.status = status; + this.message = message; + Object.setPrototypeOf(this, new.target.prototype); // Restore prototype chain + } + } + + + export class BaseError extends Error { + type: string; + message: string; + source: string; + ignoreLog: boolean; + + constructor( + type: string, + message?: string, + source?: string, + ignoreLog = false + ) { + super(); + + Object.setPrototypeOf(this, new.target.prototype); + + this.type = type; + this.message = + message ?? + "An unknown error occurred. If this persists, please contact us."; + this.source = source ?? "unspecified"; + this.ignoreLog = ignoreLog; + } + + toJSON(): Record { + return { + type: this.type, + message: this.message, + source: this.source, + }; + } + } \ No newline at end of file -- cgit v1.2.3