feat: Add base and early exit error classes
This commit is contained in:
17
packages/backend/src/errors/base.ts
Normal file
17
packages/backend/src/errors/base.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
export default class BaseError extends Error {
|
||||||
|
error = {};
|
||||||
|
|
||||||
|
constructor(error?: string | IJSONObject) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.error = JSON.parse(error as string);
|
||||||
|
} catch {
|
||||||
|
this.error = typeof error === 'string' ? { error } : error;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.name = this.constructor.name;
|
||||||
|
}
|
||||||
|
}
|
3
packages/backend/src/errors/early-exit.ts
Normal file
3
packages/backend/src/errors/early-exit.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import BaseError from './base';
|
||||||
|
|
||||||
|
export default class EarlyExitError extends BaseError {}
|
Reference in New Issue
Block a user