mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 22:16:29 +01:00
create base error class & unified error import #3
This commit is contained in:
parent
04ae271e1e
commit
6b61bd0df3
4 changed files with 29 additions and 15 deletions
|
|
@ -1,15 +1,8 @@
|
||||||
// Error classes for background jobs
|
// Error classes for background jobs
|
||||||
|
import { BaseError } from "./base-error";
|
||||||
|
|
||||||
// Class for custom background errors
|
// Class for custom background errors
|
||||||
export class BackgroundJobError extends Error{
|
export class BackgroundJobError extends BaseError{}
|
||||||
cause?: unknown;
|
|
||||||
|
|
||||||
constructor(message: string, cause?: unknown){
|
|
||||||
super(message);
|
|
||||||
this.name = this.constructor.name;
|
|
||||||
this.cause = cause;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Errors based on class BackgroundJobError
|
// Errors based on class BackgroundJobError
|
||||||
export class BackgroundDatabaseError extends 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{
|
export class AttractionImportError extends BackgroundJobError{
|
||||||
constructor(cause?: unknown){
|
constructor(cause?: unknown){
|
||||||
super('Failed to import attractions into database.', cause);
|
super('Failed to import attractions into database.', cause);
|
||||||
|
|
|
||||||
10
api/src/errors/base-error.ts
Normal file
10
api/src/errors/base-error.ts
Normal 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
3
api/src/errors/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './background-error'
|
||||||
|
export * from './http-error'
|
||||||
|
export * from './lib-error'
|
||||||
14
api/src/errors/lib-error.ts
Normal file
14
api/src/errors/lib-error.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue