-
Notifications
You must be signed in to change notification settings - Fork 110
/
errors.ts
50 lines (47 loc) · 1.21 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
import { NetworkError } from '@taquito/core';
import { STATUS_CODE } from './status_code';
/**
* @category Error
* @description Error that indicates a general failure in making the HTTP request
*/
export class HttpRequestFailed extends NetworkError {
constructor(
public readonly method: string,
public readonly url: string,
public readonly cause: Error
) {
super();
this.name = 'HttpRequestFailed';
this.message = `${method} ${url} ${String(cause)}`;
}
}
/**
* @category Error
* @description Error thrown when the endpoint returns an HTTP error to the client
*/
export class HttpResponseError extends NetworkError {
constructor(
public readonly message: string,
public readonly status: STATUS_CODE,
public readonly statusText: string,
public readonly body: string,
public readonly url: string
) {
super();
this.name = 'HttpResponseError';
}
}
/**
* @category Error
* @description Error
*/
export class HttpTimeoutError extends NetworkError {
constructor(
public readonly timeout: number,
public readonly url: string
) {
super();
this.name = 'HttpTimeoutError';
this.message = `HTTP request timeout of ${timeout}ms exceeded`;
}
}