mirror of
https://github.com/michivonah/themepark-assistant.git
synced 2025-12-22 22:16:29 +01:00
improve error handling in background jobs #3
This commit is contained in:
parent
6a60e3c10a
commit
04ae271e1e
8 changed files with 75 additions and 27 deletions
49
api/src/errors/background-error.ts
Normal file
49
api/src/errors/background-error.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
// Error classes for background jobs
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
// Errors based on class BackgroundJobError
|
||||
export class BackgroundDatabaseError extends BackgroundJobError{
|
||||
constructor(cause?: unknown){
|
||||
super('Database request failed.', cause);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
export class ThemeparkUpdateError extends BackgroundJobError{
|
||||
constructor(cause?: unknown){
|
||||
super('Failed to update themepark data.', cause);
|
||||
}
|
||||
}
|
||||
|
||||
export class KVParseError extends BackgroundJobError{
|
||||
constructor(key: string, cause?: unknown){
|
||||
super(`Failed to parse JSON from KV, affected key: ${key}`, cause);
|
||||
}
|
||||
}
|
||||
|
||||
export class SendNotificationError extends BackgroundJobError{
|
||||
constructor(cause?: unknown){
|
||||
super('Failed to send notification.', cause);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue