diff options
author | HampusM <hampus@hampusmat.com> | 2021-07-21 22:00:04 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-07-21 22:00:04 +0200 |
commit | 7b9fca8d0061cf5e5af08cba98e9d5b6dbbed8ec (patch) | |
tree | 2a75dfaaa495c90e5519012e2c8e20ab0bd7ac4e /packages/server/src/git/error.ts | |
parent | c0eb6635964de276b44851df67fb857ae94dc401 (diff) |
Began with better backend error handling & cleaned up the backend
Diffstat (limited to 'packages/server/src/git/error.ts')
-rw-r--r-- | packages/server/src/git/error.ts | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/server/src/git/error.ts b/packages/server/src/git/error.ts new file mode 100644 index 0000000..0429a6c --- /dev/null +++ b/packages/server/src/git/error.ts @@ -0,0 +1,49 @@ +export abstract class BaseError implements Error { + code: number; + name: string; + message: string; + stack?: string | undefined; + + constructor(code: number, message: string) { + this.name = "Githermit Error"; + + this.code = code; + this.message = message; + } +} + +export class RepositoryError extends BaseError { + constructor(code: number, message: string) { + super(code, "A repository error has occured: " + message); + } +} + +export class BranchError extends BaseError { + constructor(code: number, message: string) { + super(code, "A branch error has occured: " + message); + } +} + +export class TagError extends BaseError { + constructor(code: number, message: string) { + super(code, "A tag error has occured: " + message); + } +} + +export class TreeError extends BaseError { + constructor(code: number, message: string) { + super(code, "A tree error has occured: " + message); + } +} + +export class BlobError extends BaseError { + constructor(code: number, message: string) { + super(code, "A blob error has occured: " + message); + } +} + +type ErrorConstructorType<T> = new (code: number, message: string) => T; + +export function createError<E extends BaseError>(ErrorConstructor: ErrorConstructorType<E>, code: number, message: string): E { + return new ErrorConstructor(code, message); +}
\ No newline at end of file |