diff --git a/api/src/errors/background-error.ts b/api/src/errors/background-error.ts index 338a5ad..d05207f 100644 --- a/api/src/errors/background-error.ts +++ b/api/src/errors/background-error.ts @@ -1,15 +1,8 @@ // Error classes for background jobs +import { BaseError } from "./base-error"; // Class for custom background errors -export class BackgroundJobError extends Error{ - cause?: unknown; - - constructor(message: string, cause?: unknown){ - super(message); - this.name = this.constructor.name; - this.cause = cause; - } -} +export class BackgroundJobError extends BaseError{} // Errors based on class BackgroundJobError export class BackgroundDatabaseError extends BackgroundJobError{ @@ -18,12 +11,6 @@ export class BackgroundDatabaseError extends BackgroundJobError{ } } -export class BackgroundFetchError extends BackgroundJobError{ - constructor(cause?: unknown){ - super('Fetching data failed', cause); - } -} - export class AttractionImportError extends BackgroundJobError{ constructor(cause?: unknown){ super('Failed to import attractions into database.', cause); diff --git a/api/src/errors/base-error.ts b/api/src/errors/base-error.ts new file mode 100644 index 0000000..3e17ce4 --- /dev/null +++ b/api/src/errors/base-error.ts @@ -0,0 +1,10 @@ +// Base for new error domains/classes +export class BaseError extends Error{ + cause?: unknown; + + constructor(message: string, cause?: unknown){ + super(message); + this.name = this.constructor.name; + this.cause = cause; + } +} \ No newline at end of file diff --git a/api/src/errors/index.ts b/api/src/errors/index.ts new file mode 100644 index 0000000..4eaca3f --- /dev/null +++ b/api/src/errors/index.ts @@ -0,0 +1,3 @@ +export * from './background-error' +export * from './http-error' +export * from './lib-error' \ No newline at end of file diff --git a/api/src/errors/lib-error.ts b/api/src/errors/lib-error.ts new file mode 100644 index 0000000..f69903a --- /dev/null +++ b/api/src/errors/lib-error.ts @@ -0,0 +1,14 @@ +// Errors in custom libs +import { BaseError } from "./base-error"; + +export class LibError extends BaseError{} + +export class FetchError extends LibError{ + constructor(cause?: unknown, source?: string){ + super( + source + ? `Fetching data from ${source} failed` + : 'Fetching data failed', + cause); + } +} \ No newline at end of file