-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.ts
67 lines (58 loc) · 1.78 KB
/
errors.ts
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
61
62
63
64
65
66
67
import { StatusCode } from "./status.ts";
/// Abstract base error with a stupid name to avoid conflict with built-in Error
export abstract class DError {
/// Requires a message and Gemini status code
constructor(public message: string,
public code: StatusCode) { }
}
/// Unexpected line ending (e.g., server requires '\r\n' but received '\n')
export class LineEndingError extends DError {
constructor(expected: string) {
super(`Server expects ${expected} line endings`,
StatusCode.BAD_REQUEST);
}
}
/// Requested resource does not exist
export class NotFoundError extends DError {
constructor(path: string) {
super(`${path} does not exist`,
StatusCode.NOT_FOUND);
}
}
/// Insufficient permissions to access requested resource
export class ForbiddenError extends DError {
constructor(path: string) {
super(`you do not have permissions to access ${path}`,
StatusCode.NOT_FOUND);
}
}
/// Proxy request received, but proxying is unsupported
export class ProxyRefusedError extends DError {
constructor(url: string) {
super(`this server does not support proxying ${url}`,
StatusCode.PROXY_REQUEST_REFUSED);
}
}
/// Resource is Gone
export class GoneError extends DError {
constructor(path: string) {
super(`${path} is Gone. Doneso. Caput.`,
StatusCode.GONE);
}
}
/// Temporary or permanent redirect
export class RedirectError extends DError {
constructor(path: string, permanent: boolean) {
super(`${path}`,
permanent ? StatusCode.REDIRECT_PERMANENT : StatusCode.REDIRECT_TEMPORARY);
}
}
/// Catch-all internal error. Bad news.
export class InternalError extends DError {
public error: Error;
constructor(e: Error) {
super("An internal error occurred",
StatusCode.PERMANENT_FAILURE);
this.error = e;
}
}