aboutsummaryrefslogtreecommitdiff
path: root/apps/backend/src/errors
diff options
context:
space:
mode:
Diffstat (limited to 'apps/backend/src/errors')
-rw-r--r--apps/backend/src/errors/baseError.ts45
-rw-r--r--apps/backend/src/errors/results.ts31
2 files changed, 0 insertions, 76 deletions
diff --git a/apps/backend/src/errors/baseError.ts b/apps/backend/src/errors/baseError.ts
deleted file mode 100644
index bccc54df..00000000
--- a/apps/backend/src/errors/baseError.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-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<PropertyKey, string> {
- return {
- type: this.type,
- message: this.message,
- source: this.source,
- };
- }
- } \ No newline at end of file
diff --git a/apps/backend/src/errors/results.ts b/apps/backend/src/errors/results.ts
deleted file mode 100644
index c5ab115b..00000000
--- a/apps/backend/src/errors/results.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { BaseError } from "./baseError";
-
-export type Result<T, E extends Error> =
- | { ok: true; value: T }
- | { ok: false; error: E };
-
-export const Ok = <T>(data: T): Result<T, never> => {
- return { ok: true, value: data };
-};
-
-export const Err = <E extends BaseError>(error: E): Result<never, E> => {
- return { ok: false, error };
-};
-
-export async function wrap<T, E extends BaseError>(
- p: Promise<T>,
- errorFactory: (err: Error, source: string) => E,
- source: string = "unspecified"
- ): Promise<Result<T, E>> {
- try {
- return Ok(await p);
- } catch (e) {
- return Err(errorFactory(e as Error, source));
- }
- }
-
-export function isErr<T, E extends Error>(
- result: Result<T, E>,
-): result is { ok: false; error: E } {
- return !result.ok;
-} \ No newline at end of file