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
50
51
52
53
54
55
56
57
58
59
60
|
import { ErrorType } from "./types";
export * from "./types";
export class ServerError extends Error {
code: number;
constructor(where: string, error_type: { code: number, message: string }) {
super(`A ${where} error has occured: ${error_type.message}`);
this.name = "Server Error";
this.code = error_type.code;
}
}
export enum ErrorWhere {
Repository = "repository",
Tree = "tree",
Tag = "tag",
Branch = "branch",
Commit = "commit",
Diff = "diff",
Misc = "misc",
Blob = "blob"
}
/**
* A error factory
*
* @param where - Where the error has occured
* @param err_type - What type of error it is
* @param args - Parameters for the error type
*
* @returns A server error
*
* @example Example usage:
* import { ErrorType, NotFoundError, createError } from "./error";
*
* throw(createError(ErrorType.Repository, NotFoundError, "chili sauce"));
*/
export function createError<T extends new (...args: string[]) => ErrorType>(where: ErrorWhere, ErrType: T, ...args: ConstructorParameters<T>): ServerError;
/**
* A error factory
*
* @param where - Where the error has occured
* @param err_type - What type of error it is
*
* @returns A server error
*
* @example Example usage:
* import { ErrorType, UnknownError, createError } from "./error";
*
* throw(createError(ErrorType.Repository, UnknownError));
*/
export function createError<T extends new () => ErrorType>(where: ErrorWhere, ErrType: T): ServerError;
export function createError<T extends new(...args: string[]) => ErrorType>(where: ErrorWhere, ErrType: T, ...args: ConstructorParameters<T>): ServerError {
return new ServerError(where, new ErrType(...args));
}
|