create base error class & unified error import #3

This commit is contained in:
Michi 2025-10-11 12:43:48 +02:00
parent 04ae271e1e
commit 6b61bd0df3
4 changed files with 29 additions and 15 deletions

View file

@ -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);

View file

@ -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;
}
}

3
api/src/errors/index.ts Normal file
View file

@ -0,0 +1,3 @@
export * from './background-error'
export * from './http-error'
export * from './lib-error'

View file

@ -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);
}
}