-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
create_error.ts
89 lines (81 loc) · 1.81 KB
/
create_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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { type Json } from 'effector';
import {
ABORT,
type AbortError,
HTTP,
type HttpError,
INVALID_DATA,
type InvalidDataError,
NETWORK,
type NetworkError,
PREPARATION,
type PreparationError,
TIMEOUT,
type TimeoutError,
CONFIGURATION,
type ConfigurationError,
} from './type';
export function invalidDataError(config: {
validationErrors: string[];
response: unknown;
}): InvalidDataError {
return {
...config,
errorType: INVALID_DATA,
explanation: 'Response was considered as invalid against a given contract',
};
}
export function timeoutError(config: { timeout: number }): TimeoutError {
return {
...config,
errorType: TIMEOUT,
explanation: 'Request was cancelled due to timeout',
};
}
export function abortError(): AbortError {
return {
errorType: ABORT,
explanation: 'Request was cancelled due to concurrency policy',
};
}
export function preparationError(config: {
response: string;
reason: string | null;
}): PreparationError {
return {
...config,
errorType: PREPARATION,
explanation: 'Extraction of data from the response was failed',
};
}
export function httpError(config: {
status: number;
statusText: string;
response: string | Json | null;
}): HttpError {
return {
...config,
errorType: HTTP,
explanation: 'Request was finished with unsuccessful HTTP code',
};
}
export function networkError(config: {
reason: string | null;
cause?: unknown;
}): NetworkError {
return {
...config,
errorType: NETWORK,
explanation: 'Request was failed due to network problems',
};
}
export function configurationError(config: {
reason: string;
validationErrors: string[];
}): ConfigurationError {
return {
...config,
errorType: CONFIGURATION,
explanation: 'Operation is misconfigured',
};
}