-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherror.ts
39 lines (35 loc) · 1.07 KB
/
error.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
/** Error which was caused by a MusicBrainz API call. */
export class ApiError extends Error {
/** HTTP status code which was returned by the API. */
statusCode: number;
constructor(message: string, statusCode?: number) {
super(message);
Object.defineProperty(this, "name", {
value: "ApiError",
enumerable: false,
});
this.statusCode = statusCode ?? 500;
}
}
/** Error which is thrown when there are too many API requests. */
export class RateLimitError extends Error {
constructor(message: string) {
super(message);
Object.defineProperty(this, "name", {
value: "RateLimitError",
enumerable: false,
});
}
}
/** Error response which is returned by the MusicBrainz `ws/2` JSON API. */
export interface ErrorResponse {
/** Error message with a description. */
error: string;
/** Usage help message with link. */
help?: string;
}
/** Checks whether the given JSON is an error response. */
// deno-lint-ignore no-explicit-any
export function isError(json: any): json is ErrorResponse {
return typeof json.error === "string";
}