/
Errors.ts
51 lines (43 loc) · 1.66 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
import { HttpStatusCode } from "../http";
/**
* Thrown on HTTP response with a non-successful status code (4xx or 5xx).
*/
export class HttpError extends Error {
/**
* Creates a new HTTP error.
* @param message The error message.
* @param status The HTTP status code.
* @param data Additional error data.
*/
constructor(message: string, public status: HttpStatusCode, public data?: any) {
super(message);
}
}
/**
* Thrown on HTTP response for a bad request (usually {@link http!HttpStatusCode.BadRequest}).
*/
export class BadRequestError extends HttpError {}
/**
* Thrown on HTTP response for an unauthenticated request, i.e. missing credentials (usually {@link http!HttpStatusCode.Unauthorized}).
*/
export class AuthenticationError extends HttpError {}
/**
* Thrown on HTTP response for an unauthorized request, i.e. missing permissions (usually {@link http!HttpStatusCode.Forbidden}).
*/
export class AuthorizationError extends HttpError {}
/**
* Thrown on HTTP response for a missing resource (usually {@link http!HttpStatusCode.NotFound} or {@link http!HttpStatusCode.Gone}).
*/
export class NotFoundError extends HttpError {}
/**
* Thrown on HTTP response for a timed-out operation (usually {@link http!HttpStatusCode.RequestTimeout}).
*/
export class TimeoutError extends HttpError {}
/**
* Thrown on HTTP response for a resource conflict (usually {@link http!HttpStatusCode.Conflict}).
*/
export class ConflictError extends HttpError {}
/**
* Thrown on HTTP response for a failed precondition or mid-air collision (usually {@link http!HttpStatusCode.PreconditionFailed}).
*/
export class ConcurrencyError extends HttpError {}