UNPKG

2.19 kBPlain TextView Raw
1type Message = string;
2
3interface Status {
4 status: number;
5 statusText: string;
6}
7
8interface ErrorDetails {
9 signature?: string;
10 raw?: any;
11}
12
13interface FetchErrorDetails extends Status {
14 headers: Headers;
15 body: string;
16}
17
18// Deprecated
19interface AxiosErrorDetails {
20 originalError: Error;
21 code?: string;
22 statusCode?: number;
23 statusMessage?: string;
24}
25
26export class SignatureValidationFailed extends Error {
27 public signature?: string;
28
29 constructor(message: Message, { signature }: ErrorDetails = {}) {
30 super(message);
31 this.name = this.constructor.name;
32
33 Object.assign(this, { signature });
34 }
35}
36
37export class JSONParseError extends Error {
38 public raw: any;
39
40 constructor(message: Message, { raw }: ErrorDetails = {}) {
41 super(message);
42 this.name = this.constructor.name;
43
44 Object.assign(this, { raw });
45 }
46}
47
48/* Deprecated */
49export class RequestError extends Error {
50 public code: string;
51
52 private originalError: Error;
53
54 constructor(message: Message, { code, originalError }: AxiosErrorDetails) {
55 super(message);
56 this.name = this.constructor.name;
57
58 Object.assign(this, { code, originalError });
59 }
60}
61
62export class ReadError extends Error {
63 public originalError: Error;
64
65 constructor(message: Message, { originalError }: AxiosErrorDetails) {
66 super(message);
67 this.name = this.constructor.name;
68
69 Object.assign(this, { originalError });
70 }
71}
72
73export class HTTPError extends Error {
74 public statusCode: number;
75
76 public statusMessage: string;
77
78 public originalError: any;
79
80 constructor(
81 message: Message,
82 { statusCode, statusMessage, originalError }: AxiosErrorDetails,
83 ) {
84 super(message);
85 this.name = this.constructor.name;
86
87 Object.assign(this, { statusCode, statusMessage, originalError });
88 }
89}
90
91export class HTTPFetchError extends Error {
92 public status: number;
93
94 public statusText: string;
95
96 public headers: Headers;
97
98 public body: string;
99
100 constructor(
101 message: Message,
102 { status, statusText, headers, body }: FetchErrorDetails,
103 ) {
104 super(message);
105 this.name = this.constructor.name;
106
107 Object.assign(this, { status, statusText, headers, body });
108 }
109}