1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | class StripeError extends Error {
|
8 | constructor(raw = {}) {
|
9 | super(raw.message);
|
10 | this.type = this.constructor.name;
|
11 |
|
12 | this.raw = raw;
|
13 | this.rawType = raw.type;
|
14 | this.code = raw.code;
|
15 | this.doc_url = raw.doc_url;
|
16 | this.param = raw.param;
|
17 | this.detail = raw.detail;
|
18 | this.headers = raw.headers;
|
19 | this.requestId = raw.requestId;
|
20 | this.statusCode = raw.statusCode;
|
21 | this.message = raw.message;
|
22 |
|
23 | this.charge = raw.charge;
|
24 | this.decline_code = raw.decline_code;
|
25 | this.payment_intent = raw.payment_intent;
|
26 | this.payment_method = raw.payment_method;
|
27 | this.setup_intent = raw.setup_intent;
|
28 | this.source = raw.source;
|
29 | }
|
30 |
|
31 | |
32 |
|
33 |
|
34 | static generate(rawStripeError) {
|
35 | switch (rawStripeError.type) {
|
36 | case 'card_error':
|
37 | return new StripeCardError(rawStripeError);
|
38 | case 'invalid_request_error':
|
39 | return new StripeInvalidRequestError(rawStripeError);
|
40 | case 'api_error':
|
41 | return new StripeAPIError(rawStripeError);
|
42 | case 'authentication_error':
|
43 | return new StripeAuthenticationError(rawStripeError);
|
44 | case 'rate_limit_error':
|
45 | return new StripeRateLimitError(rawStripeError);
|
46 | case 'idempotency_error':
|
47 | return new StripeIdempotencyError(rawStripeError);
|
48 | case 'invalid_grant':
|
49 | return new StripeInvalidGrantError(rawStripeError);
|
50 | default:
|
51 | return new GenericError('Generic', 'Unknown Error');
|
52 | }
|
53 | }
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | class StripeCardError extends StripeError {}
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | class StripeInvalidRequestError extends StripeError {}
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 | class StripeAPIError extends StripeError {}
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | class StripeAuthenticationError extends StripeError {}
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | class StripePermissionError extends StripeError {}
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 | class StripeRateLimitError extends StripeError {}
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | class StripeConnectionError extends StripeError {}
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | class StripeSignatureVerificationError extends StripeError {}
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | class StripeIdempotencyError extends StripeError {}
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | class StripeInvalidGrantError extends StripeError {}
|
123 |
|
124 | module.exports.generate = StripeError.generate;
|
125 | module.exports.StripeError = StripeError;
|
126 | module.exports.StripeCardError = StripeCardError;
|
127 | module.exports.StripeInvalidRequestError = StripeInvalidRequestError;
|
128 | module.exports.StripeAPIError = StripeAPIError;
|
129 | module.exports.StripeAuthenticationError = StripeAuthenticationError;
|
130 | module.exports.StripePermissionError = StripePermissionError;
|
131 | module.exports.StripeRateLimitError = StripeRateLimitError;
|
132 | module.exports.StripeConnectionError = StripeConnectionError;
|
133 | module.exports.StripeSignatureVerificationError = StripeSignatureVerificationError;
|
134 | module.exports.StripeIdempotencyError = StripeIdempotencyError;
|
135 | module.exports.StripeInvalidGrantError = StripeInvalidGrantError;
|