aboutsummaryrefslogtreecommitdiff
path: root/packages/server/src/git/error.ts
blob: 0429a6cd175780e706939f516951417fb72c12d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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);
}