@beemafrica/error-definitions 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -0
- package/dist/definitions.d.ts +4 -0
- package/dist/definitions.d.ts.map +1 -0
- package/dist/definitions.js +327 -0
- package/dist/definitions.js.map +1 -0
- package/dist/factory.d.ts +27 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +74 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/standard-error.d.ts +13 -0
- package/dist/standard-error.d.ts.map +1 -0
- package/dist/standard-error.js +41 -0
- package/dist/standard-error.js.map +1 -0
- package/dist/types/index.d.ts +55 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +15 -0
- package/dist/types/index.js.map +1 -0
- package/dist-cjs/definitions.js +331 -0
- package/dist-cjs/definitions.js.map +1 -0
- package/dist-cjs/factory.js +81 -0
- package/dist-cjs/factory.js.map +1 -0
- package/dist-cjs/index.js +19 -0
- package/dist-cjs/index.js.map +1 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/standard-error.js +46 -0
- package/dist-cjs/standard-error.js.map +1 -0
- package/dist-cjs/types/index.js +18 -0
- package/dist-cjs/types/index.js.map +1 -0
- package/package.json +49 -0
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
## Error Definitions (BeemM)
|
|
2
|
+
|
|
3
|
+
This package provides canonical error codes and helpers for building consistent error responses across services.
|
|
4
|
+
|
|
5
|
+
## Start here
|
|
6
|
+
|
|
7
|
+
- **Consumer guide**: see `CONSUMER_GUIDE.md` for real-world usage patterns (API boundaries, middleware, service-to-service errors, dependency failures, and expected response shapes).
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
Create/throw canonical errors in your service code:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createError } from "error-definitions";
|
|
15
|
+
|
|
16
|
+
throw createError("API_INVALID_REQUEST_FORMAT", {
|
|
17
|
+
context: { source: "request-body" },
|
|
18
|
+
traceId,
|
|
19
|
+
});
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Normalize any unknown error at the boundary (and use `status_code` as the HTTP status):
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { toErrorResponse } from "error-definitions";
|
|
26
|
+
|
|
27
|
+
const payload = toErrorResponse(err, { traceId });
|
|
28
|
+
res.status(payload.status_code).json(payload);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## CommonJS support (`require`)
|
|
32
|
+
|
|
33
|
+
This package supports both ESM and CommonJS consumers.
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
// CommonJS
|
|
37
|
+
const { createError, ServiceId } = require("error-definitions");
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Dependency tracking
|
|
41
|
+
|
|
42
|
+
`BMErrorResponse` supports an optional `dependency` object to capture **what dependency failed** and the **raw dependency error**:
|
|
43
|
+
|
|
44
|
+
- **name**: e.g. `Redis`, `Stripe`, `RabbitMQ`
|
|
45
|
+
- **type**: `INTERNAL` | `EXTERNAL`
|
|
46
|
+
- **original_message**: raw message from the caught error
|
|
47
|
+
|
|
48
|
+
### Which code should I use?
|
|
49
|
+
|
|
50
|
+
- **INFRASTRUCTURE_FAILURE**: internal tools/infrastructure dependencies (e.g. Redis, RabbitMQ)
|
|
51
|
+
- **THIRD_PARTY_ERROR**: external vendors/providers (e.g. Stripe)
|
|
52
|
+
|
|
53
|
+
### Helper: `handleDependencyError`
|
|
54
|
+
|
|
55
|
+
Use `handleDependencyError` inside a `try/catch` to convert a raw dependency exception into a `BMErrorResponse` with the correct canonical code and populated `dependency.original_message`.
|
|
56
|
+
|
|
57
|
+
Example:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { handleDependencyError, ServiceId } from "error-definitions";
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await stripe.charges.create(...);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
return handleDependencyError(
|
|
66
|
+
ServiceId.Payments,
|
|
67
|
+
{ name: "Stripe", type: "EXTERNAL" },
|
|
68
|
+
err,
|
|
69
|
+
{ trace_id }
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CanonicalErrorCode, ErrorDefinition } from "./types/index.js";
|
|
2
|
+
export declare const ERROR_DEFINITIONS: Readonly<Record<CanonicalErrorCode, ErrorDefinition>>;
|
|
3
|
+
export declare function getErrorDefinition(code: CanonicalErrorCode): ErrorDefinition;
|
|
4
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../definitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE5E,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,MAAM,CAAC,kBAAkB,EAAE,eAAe,CAAC,CA2UnF,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,kBAAkB,GAAG,eAAe,CAE5E"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
export const ERROR_DEFINITIONS = {
|
|
2
|
+
INTERNAL_ERROR: {
|
|
3
|
+
code: "INTERNAL_ERROR",
|
|
4
|
+
httpStatus: 500,
|
|
5
|
+
retryable: false,
|
|
6
|
+
defaultMessage: "Unexpected server error.",
|
|
7
|
+
},
|
|
8
|
+
INVALID_ARGUMENT: {
|
|
9
|
+
code: "INVALID_ARGUMENT",
|
|
10
|
+
httpStatus: 400,
|
|
11
|
+
retryable: false,
|
|
12
|
+
defaultMessage: "Invalid argument.",
|
|
13
|
+
},
|
|
14
|
+
SERVICE_FAILURE: {
|
|
15
|
+
code: "SERVICE_FAILURE",
|
|
16
|
+
httpStatus: 500,
|
|
17
|
+
retryable: true,
|
|
18
|
+
defaultMessage: "Service failed to process the request.",
|
|
19
|
+
},
|
|
20
|
+
// UI Errors
|
|
21
|
+
UI_INVALID_INPUT: {
|
|
22
|
+
code: "UI_INVALID_INPUT",
|
|
23
|
+
httpStatus: 400,
|
|
24
|
+
retryable: false,
|
|
25
|
+
defaultMessage: "Input provided is invalid.",
|
|
26
|
+
},
|
|
27
|
+
UI_REQUIRED_FIELD_MISSING: {
|
|
28
|
+
code: "UI_REQUIRED_FIELD_MISSING",
|
|
29
|
+
httpStatus: 400,
|
|
30
|
+
retryable: false,
|
|
31
|
+
defaultMessage: "A required field is missing.",
|
|
32
|
+
},
|
|
33
|
+
UI_INVALID_FORMAT: {
|
|
34
|
+
code: "UI_INVALID_FORMAT",
|
|
35
|
+
httpStatus: 400,
|
|
36
|
+
retryable: false,
|
|
37
|
+
defaultMessage: "Input format is incorrect.",
|
|
38
|
+
},
|
|
39
|
+
UI_FILE_TOO_LARGE: {
|
|
40
|
+
code: "UI_FILE_TOO_LARGE",
|
|
41
|
+
httpStatus: 413,
|
|
42
|
+
retryable: false,
|
|
43
|
+
defaultMessage: "Uploaded file exceeds size limit.",
|
|
44
|
+
},
|
|
45
|
+
UI_UNSUPPORTED_FILE_TYPE: {
|
|
46
|
+
code: "UI_UNSUPPORTED_FILE_TYPE",
|
|
47
|
+
httpStatus: 415,
|
|
48
|
+
retryable: false,
|
|
49
|
+
defaultMessage: "File type is not supported.",
|
|
50
|
+
},
|
|
51
|
+
UI_STALE_STATE: {
|
|
52
|
+
code: "UI_STALE_STATE",
|
|
53
|
+
httpStatus: 409,
|
|
54
|
+
retryable: false,
|
|
55
|
+
defaultMessage: "UI state is outdated; refresh required.",
|
|
56
|
+
},
|
|
57
|
+
UI_ACTION_NOT_AVAILABLE: {
|
|
58
|
+
code: "UI_ACTION_NOT_AVAILABLE",
|
|
59
|
+
httpStatus: 403,
|
|
60
|
+
retryable: false,
|
|
61
|
+
defaultMessage: "Action is not allowed in current state.",
|
|
62
|
+
},
|
|
63
|
+
UI_DUPLICATE_SUBMISSION: {
|
|
64
|
+
code: "UI_DUPLICATE_SUBMISSION",
|
|
65
|
+
httpStatus: 409,
|
|
66
|
+
retryable: false,
|
|
67
|
+
defaultMessage: "Duplicate submission detected.",
|
|
68
|
+
},
|
|
69
|
+
UI_RENDER_ERROR: {
|
|
70
|
+
code: "UI_RENDER_ERROR",
|
|
71
|
+
httpStatus: 500,
|
|
72
|
+
retryable: false,
|
|
73
|
+
defaultMessage: "UI failed to render correctly.",
|
|
74
|
+
},
|
|
75
|
+
UI_ASSET_LOAD_FAILED: {
|
|
76
|
+
code: "UI_ASSET_LOAD_FAILED",
|
|
77
|
+
httpStatus: 500,
|
|
78
|
+
retryable: false,
|
|
79
|
+
defaultMessage: "Required asset failed to load.",
|
|
80
|
+
},
|
|
81
|
+
UI_TRANSLATION_MISSING: {
|
|
82
|
+
code: "UI_TRANSLATION_MISSING",
|
|
83
|
+
httpStatus: 500,
|
|
84
|
+
retryable: false,
|
|
85
|
+
defaultMessage: "Missing translation resource.",
|
|
86
|
+
},
|
|
87
|
+
// API Errors - Validation Errors
|
|
88
|
+
API_INVALID_PARAMETER: {
|
|
89
|
+
code: "API_INVALID_PARAMETER",
|
|
90
|
+
httpStatus: 400,
|
|
91
|
+
retryable: true,
|
|
92
|
+
defaultMessage: "Parameter value invalid.",
|
|
93
|
+
},
|
|
94
|
+
API_REQUIRED_PARAMETER_MISSING: {
|
|
95
|
+
code: "API_REQUIRED_PARAMETER_MISSING",
|
|
96
|
+
httpStatus: 400,
|
|
97
|
+
retryable: true,
|
|
98
|
+
defaultMessage: "Required parameter missing.",
|
|
99
|
+
},
|
|
100
|
+
API_INVALID_REQUEST_FORMAT: {
|
|
101
|
+
code: "API_INVALID_REQUEST_FORMAT",
|
|
102
|
+
httpStatus: 400,
|
|
103
|
+
retryable: true,
|
|
104
|
+
defaultMessage: "Request format is invalid.",
|
|
105
|
+
},
|
|
106
|
+
API_SCHEMA_VALIDATION_FAILED: {
|
|
107
|
+
code: "API_SCHEMA_VALIDATION_FAILED",
|
|
108
|
+
httpStatus: 400,
|
|
109
|
+
retryable: true,
|
|
110
|
+
defaultMessage: "Request schema validation failed.",
|
|
111
|
+
},
|
|
112
|
+
API_TOO_MANY_ITEMS: {
|
|
113
|
+
code: "API_TOO_MANY_ITEMS",
|
|
114
|
+
httpStatus: 429,
|
|
115
|
+
retryable: true,
|
|
116
|
+
defaultMessage: "Request contains too many items.",
|
|
117
|
+
},
|
|
118
|
+
API_FIELD_TOO_LONG: {
|
|
119
|
+
code: "API_FIELD_TOO_LONG",
|
|
120
|
+
httpStatus: 400,
|
|
121
|
+
retryable: true,
|
|
122
|
+
defaultMessage: "Field exceeds maximum length.",
|
|
123
|
+
},
|
|
124
|
+
API_UNSUPPORTED_VALUE: {
|
|
125
|
+
code: "API_UNSUPPORTED_VALUE",
|
|
126
|
+
httpStatus: 400,
|
|
127
|
+
retryable: true,
|
|
128
|
+
defaultMessage: "Parameter contains an unsupported value.",
|
|
129
|
+
},
|
|
130
|
+
// API Errors - Authentication Errors
|
|
131
|
+
AUTH_MISSING_CREDENTIALS: {
|
|
132
|
+
code: "AUTH_MISSING_CREDENTIALS",
|
|
133
|
+
httpStatus: 401,
|
|
134
|
+
retryable: true,
|
|
135
|
+
defaultMessage: "Required credentials missing.",
|
|
136
|
+
},
|
|
137
|
+
AUTH_INVALID_CREDENTIALS: {
|
|
138
|
+
code: "AUTH_INVALID_CREDENTIALS",
|
|
139
|
+
httpStatus: 401,
|
|
140
|
+
retryable: true,
|
|
141
|
+
defaultMessage: "Credentials invalid.",
|
|
142
|
+
},
|
|
143
|
+
AUTH_FORBIDDEN: {
|
|
144
|
+
code: "AUTH_FORBIDDEN",
|
|
145
|
+
httpStatus: 403,
|
|
146
|
+
retryable: true,
|
|
147
|
+
defaultMessage: "Access forbidden.",
|
|
148
|
+
},
|
|
149
|
+
AUTH_INSUFFICIENT_PERMISSIONS: {
|
|
150
|
+
code: "AUTH_INSUFFICIENT_PERMISSIONS",
|
|
151
|
+
httpStatus: 403,
|
|
152
|
+
retryable: true,
|
|
153
|
+
defaultMessage: "Not enough permissions.",
|
|
154
|
+
},
|
|
155
|
+
AUTH_TOKEN_EXPIRED: {
|
|
156
|
+
code: "AUTH_TOKEN_EXPIRED",
|
|
157
|
+
httpStatus: 401,
|
|
158
|
+
retryable: true,
|
|
159
|
+
defaultMessage: "Auth token expired.",
|
|
160
|
+
},
|
|
161
|
+
// API Errors - Business Logic Errors
|
|
162
|
+
DOMAIN_INCORRECT_PIN: {
|
|
163
|
+
code: "DOMAIN_INCORRECT_PIN",
|
|
164
|
+
httpStatus: 400,
|
|
165
|
+
retryable: true,
|
|
166
|
+
defaultMessage: "OTP Pin is incorrect.",
|
|
167
|
+
},
|
|
168
|
+
DOMAIN_PIN_EXPIRED: {
|
|
169
|
+
code: "DOMAIN_PIN_EXPIRED",
|
|
170
|
+
httpStatus: 400,
|
|
171
|
+
retryable: true,
|
|
172
|
+
defaultMessage: "OTP Pin expired.",
|
|
173
|
+
},
|
|
174
|
+
DOMAIN_OTP_ATTEMPTS_EXCEEDED: {
|
|
175
|
+
code: "DOMAIN_OTP_ATTEMPTS_EXCEEDED",
|
|
176
|
+
httpStatus: 429,
|
|
177
|
+
retryable: true,
|
|
178
|
+
defaultMessage: "OTP attempts exceeded.",
|
|
179
|
+
},
|
|
180
|
+
DOMAIN_DUPLICATE_PIN: {
|
|
181
|
+
code: "DOMAIN_DUPLICATE_PIN",
|
|
182
|
+
httpStatus: 409,
|
|
183
|
+
retryable: true,
|
|
184
|
+
defaultMessage: "OTP Pin already used.",
|
|
185
|
+
},
|
|
186
|
+
DOMAIN_INVALID_SCHEDULE_TIME: {
|
|
187
|
+
code: "DOMAIN_INVALID_SCHEDULE_TIME",
|
|
188
|
+
httpStatus: 400,
|
|
189
|
+
retryable: true,
|
|
190
|
+
defaultMessage: "Scheduled time invalid.",
|
|
191
|
+
},
|
|
192
|
+
DOMAIN_RESOURCE_CONFLICT: {
|
|
193
|
+
code: "DOMAIN_RESOURCE_CONFLICT",
|
|
194
|
+
httpStatus: 409,
|
|
195
|
+
retryable: true,
|
|
196
|
+
defaultMessage: "Resource conflict detected.",
|
|
197
|
+
},
|
|
198
|
+
DOMAIN_RESOURCE_NOT_FOUND: {
|
|
199
|
+
code: "DOMAIN_RESOURCE_NOT_FOUND",
|
|
200
|
+
httpStatus: 404,
|
|
201
|
+
retryable: true,
|
|
202
|
+
defaultMessage: "Resource not found.",
|
|
203
|
+
},
|
|
204
|
+
// API Errors - Dependency & Integration Errors
|
|
205
|
+
DEPENDENCY_FAILURE: {
|
|
206
|
+
code: "DEPENDENCY_FAILURE",
|
|
207
|
+
httpStatus: 502,
|
|
208
|
+
retryable: true,
|
|
209
|
+
defaultMessage: "A required downstream service is down.",
|
|
210
|
+
},
|
|
211
|
+
DEPENDENCY_TIMEOUT: {
|
|
212
|
+
code: "DEPENDENCY_TIMEOUT",
|
|
213
|
+
httpStatus: 504,
|
|
214
|
+
retryable: true,
|
|
215
|
+
defaultMessage: "Downstream service responded too slowly.",
|
|
216
|
+
},
|
|
217
|
+
INFRASTRUCTURE_FAILURE: {
|
|
218
|
+
code: "INFRASTRUCTURE_FAILURE",
|
|
219
|
+
httpStatus: 503,
|
|
220
|
+
retryable: true,
|
|
221
|
+
defaultMessage: "An internal infrastructure dependency failed.",
|
|
222
|
+
},
|
|
223
|
+
THIRD_PARTY_ERROR: {
|
|
224
|
+
code: "THIRD_PARTY_ERROR",
|
|
225
|
+
httpStatus: 502,
|
|
226
|
+
retryable: true,
|
|
227
|
+
defaultMessage: "A third-party provider returned an error.",
|
|
228
|
+
},
|
|
229
|
+
UPSTREAM_ERROR: {
|
|
230
|
+
code: "UPSTREAM_ERROR",
|
|
231
|
+
httpStatus: 502,
|
|
232
|
+
retryable: false,
|
|
233
|
+
defaultMessage: "Downstream service returned an invalid response.",
|
|
234
|
+
},
|
|
235
|
+
// API Errors - Rate Limiting Errors
|
|
236
|
+
RESOURCE_EXHAUSTED: {
|
|
237
|
+
code: "RESOURCE_EXHAUSTED",
|
|
238
|
+
httpStatus: 429,
|
|
239
|
+
retryable: true,
|
|
240
|
+
defaultMessage: "User has hit their rate limit.",
|
|
241
|
+
},
|
|
242
|
+
QUOTA_EXCEEDED: {
|
|
243
|
+
code: "QUOTA_EXCEEDED",
|
|
244
|
+
httpStatus: 403,
|
|
245
|
+
retryable: false,
|
|
246
|
+
defaultMessage: "Monthly billing limit reached.",
|
|
247
|
+
},
|
|
248
|
+
SERVER_OVERLOAD: {
|
|
249
|
+
code: "SERVER_OVERLOAD",
|
|
250
|
+
httpStatus: 503,
|
|
251
|
+
retryable: true,
|
|
252
|
+
defaultMessage: "System is too busy to handle the request; back off immediately.",
|
|
253
|
+
},
|
|
254
|
+
// API Errors - Concurrency & State Errors
|
|
255
|
+
CONCURRENCY_CONFLICT: {
|
|
256
|
+
code: "CONCURRENCY_CONFLICT",
|
|
257
|
+
httpStatus: 409,
|
|
258
|
+
retryable: true,
|
|
259
|
+
defaultMessage: "Conflict detected. Please refresh and try again.",
|
|
260
|
+
},
|
|
261
|
+
ABORTED: {
|
|
262
|
+
code: "ABORTED",
|
|
263
|
+
httpStatus: 409,
|
|
264
|
+
retryable: true,
|
|
265
|
+
defaultMessage: "Conflict detected.",
|
|
266
|
+
},
|
|
267
|
+
OUT_OF_RANGE: {
|
|
268
|
+
code: "OUT_OF_RANGE",
|
|
269
|
+
httpStatus: 400,
|
|
270
|
+
retryable: false,
|
|
271
|
+
defaultMessage: "Client navigated beyond the valid state.",
|
|
272
|
+
},
|
|
273
|
+
ALREADY_EXISTS: {
|
|
274
|
+
code: "ALREADY_EXISTS",
|
|
275
|
+
httpStatus: 409,
|
|
276
|
+
retryable: false,
|
|
277
|
+
defaultMessage: "Resource already exists.",
|
|
278
|
+
},
|
|
279
|
+
// API Errors - Network Errors
|
|
280
|
+
NETWORK_TIMEOUT: {
|
|
281
|
+
code: "NETWORK_TIMEOUT",
|
|
282
|
+
httpStatus: 408,
|
|
283
|
+
retryable: true,
|
|
284
|
+
defaultMessage: "The client started a request but did not finish sending it in time.",
|
|
285
|
+
},
|
|
286
|
+
PAYLOAD_TOO_LARGE: {
|
|
287
|
+
code: "PAYLOAD_TOO_LARGE",
|
|
288
|
+
httpStatus: 413,
|
|
289
|
+
retryable: false,
|
|
290
|
+
defaultMessage: "The request body exceeds the network limit.",
|
|
291
|
+
},
|
|
292
|
+
TOO_MANY_REQUESTS: {
|
|
293
|
+
code: "TOO_MANY_REQUESTS",
|
|
294
|
+
httpStatus: 429,
|
|
295
|
+
retryable: true,
|
|
296
|
+
defaultMessage: "Network-level rate limiter blocked the request.",
|
|
297
|
+
},
|
|
298
|
+
CLIENT_CLOSED_REQUEST: {
|
|
299
|
+
code: "CLIENT_CLOSED_REQUEST",
|
|
300
|
+
httpStatus: 499,
|
|
301
|
+
retryable: false,
|
|
302
|
+
defaultMessage: "Client cancelled the request before the server finished.",
|
|
303
|
+
},
|
|
304
|
+
// API Errors - Server-Side Infrastructure Errors
|
|
305
|
+
GATEWAY_TIMEOUT: {
|
|
306
|
+
code: "GATEWAY_TIMEOUT",
|
|
307
|
+
httpStatus: 504,
|
|
308
|
+
retryable: true,
|
|
309
|
+
defaultMessage: "API gateway timed out waiting for upstream service.",
|
|
310
|
+
},
|
|
311
|
+
BAD_GATEWAY: {
|
|
312
|
+
code: "BAD_GATEWAY",
|
|
313
|
+
httpStatus: 502,
|
|
314
|
+
retryable: true,
|
|
315
|
+
defaultMessage: "Server received an invalid response from upstream.",
|
|
316
|
+
},
|
|
317
|
+
SERVICE_UNAVAILABLE: {
|
|
318
|
+
code: "SERVICE_UNAVAILABLE",
|
|
319
|
+
httpStatus: 503,
|
|
320
|
+
retryable: true,
|
|
321
|
+
defaultMessage: "Service unavailable.",
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
export function getErrorDefinition(code) {
|
|
325
|
+
return ERROR_DEFINITIONS[code];
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../definitions.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAA0D;IACvF,cAAc,EAAE;QACf,IAAI,EAAE,gBAAgB;QACtB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,0BAA0B;KAC1C;IACD,gBAAgB,EAAE;QACjB,IAAI,EAAE,kBAAkB;QACxB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,mBAAmB;KACnC;IACD,eAAe,EAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,wCAAwC;KACxD;IAED,YAAY;IACZ,gBAAgB,EAAE;QACjB,IAAI,EAAE,kBAAkB;QACxB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,4BAA4B;KAC5C;IACD,yBAAyB,EAAE;QAC1B,IAAI,EAAE,2BAA2B;QACjC,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,8BAA8B;KAC9C;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,mBAAmB;QACzB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,4BAA4B;KAC5C;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,mBAAmB;QACzB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,mCAAmC;KACnD;IACD,wBAAwB,EAAE;QACzB,IAAI,EAAE,0BAA0B;QAChC,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,6B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AE,KAAK;QAChB,cAAc,EAAE,6CAA6C;KAC7D;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,mBAAmB;QACzB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,iDAAiD;KACjE;IACD,qBAAqB,EAAE;QACtB,IAAI,EAAE,uBAAuB;QAC7B,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,KAAK;QAChB,cAAc,EAAE,0DAA0D;KAC1E;IAED,iDAAiD;IACjD,eAAe,EAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,qDAAqD;KACrE;IACD,WAAW,EAAE;QACZ,IAAI,EAAE,aAAa;QACnB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,oDAAoD;KACpE;IACD,mBAAmB,EAAE;QACpB,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,sBAAsB;KACtC;CACD,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,IAAwB;IAC1D,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { StandardError } from "./standard-error.js";
|
|
2
|
+
import type { BMErrorResponse, CanonicalErrorCode, CanonicalError, CreateErrorOptions, ErrorContext, StandardErrorResponse, TraceId } from "./types/index.js";
|
|
3
|
+
import { ServiceId } from "./types/index.js";
|
|
4
|
+
export declare function createError(code: CanonicalErrorCode, options?: CreateErrorOptions): StandardError;
|
|
5
|
+
export declare function getCanonicalError(code: CanonicalErrorCode): CanonicalError;
|
|
6
|
+
export declare function createErrorResponse(code: CanonicalErrorCode, options?: CreateErrorOptions): StandardErrorResponse;
|
|
7
|
+
export declare function wrapServiceError(serviceId: ServiceId, baseError: CanonicalError, overrides: Readonly<{
|
|
8
|
+
message: string;
|
|
9
|
+
internal_code?: number | string;
|
|
10
|
+
dependency?: BMErrorResponse["dependency"];
|
|
11
|
+
context?: ErrorContext;
|
|
12
|
+
trace_id?: TraceId;
|
|
13
|
+
}>): BMErrorResponse;
|
|
14
|
+
export declare function handleDependencyError(serviceId: ServiceId, dependency: Readonly<{
|
|
15
|
+
name: string;
|
|
16
|
+
type: "INTERNAL" | "EXTERNAL";
|
|
17
|
+
}>, err: unknown, options?: Readonly<{
|
|
18
|
+
message?: string;
|
|
19
|
+
internal_code?: number | string;
|
|
20
|
+
context?: ErrorContext;
|
|
21
|
+
trace_id?: TraceId;
|
|
22
|
+
}>): BMErrorResponse;
|
|
23
|
+
export declare function toErrorResponse(err: unknown, options?: Readonly<{
|
|
24
|
+
fallbackCode?: CanonicalErrorCode;
|
|
25
|
+
traceId?: TraceId;
|
|
26
|
+
}>): StandardErrorResponse;
|
|
27
|
+
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAmB,MAAM,qBAAqB,CAAC;AACrE,OAAO,KAAK,EACX,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,OAAO,EACP,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAY7C,wBAAgB,WAAW,CAAC,IAAI,EAAE,kBAAkB,EAAE,OAAO,GAAE,kBAAuB,GAAG,aAAa,CAErG;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,kBAAkB,GAAG,cAAc,CAO1E;AAED,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,kBAAkB,EACxB,OAAO,GAAE,kBAAuB,GAC9B,qBAAqB,CAEvB;AAED,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,cAAc,EACzB,SAAS,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,UAAU,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC3C,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC,GACA,eAAe,CAYjB;AAED,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,QAAQ,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAA;CAAE,CAAC,EACrE,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,QAAQ,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB,CAAM,GACL,eAAe,CAoBjB;AAED,wBAAgB,eAAe,CAC9B,GAAG,EAAE,OAAO,EACZ,OAAO,CAAC,EAAE,QAAQ,CAAC;IAAE,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GAC1E,qBAAqB,CAkBvB"}
|
package/dist/factory.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { getErrorDefinition } from "./definitions.js";
|
|
2
|
+
import { StandardError, isStandardError } from "./standard-error.js";
|
|
3
|
+
import { ServiceId } from "./types/index.js";
|
|
4
|
+
function getOriginalMessage(err) {
|
|
5
|
+
if (err instanceof Error && typeof err.message === "string" && err.message.length > 0)
|
|
6
|
+
return err.message;
|
|
7
|
+
if (typeof err === "string" && err.length > 0)
|
|
8
|
+
return err;
|
|
9
|
+
try {
|
|
10
|
+
return JSON.stringify(err);
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return "Unknown dependency error.";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function createError(code, options = {}) {
|
|
17
|
+
return new StandardError(code, options);
|
|
18
|
+
}
|
|
19
|
+
export function getCanonicalError(code) {
|
|
20
|
+
const def = getErrorDefinition(code);
|
|
21
|
+
return {
|
|
22
|
+
error_code: def.code,
|
|
23
|
+
status_code: def.httpStatus,
|
|
24
|
+
retryable: def.retryable,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export function createErrorResponse(code, options = {}) {
|
|
28
|
+
return createError(code, options).toJSON();
|
|
29
|
+
}
|
|
30
|
+
export function wrapServiceError(serviceId, baseError, overrides) {
|
|
31
|
+
return {
|
|
32
|
+
service_id: serviceId,
|
|
33
|
+
error_code: baseError.error_code,
|
|
34
|
+
message: overrides.message,
|
|
35
|
+
code: baseError.status_code,
|
|
36
|
+
retryable: baseError.retryable,
|
|
37
|
+
...(overrides.internal_code !== undefined ? { internal_code: overrides.internal_code } : {}),
|
|
38
|
+
...(overrides.dependency !== undefined ? { dependency: overrides.dependency } : {}),
|
|
39
|
+
...(overrides.context !== undefined ? { context: overrides.context } : {}),
|
|
40
|
+
...(overrides.trace_id !== undefined ? { trace_id: overrides.trace_id } : {}),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function handleDependencyError(serviceId, dependency, err, options = {}) {
|
|
44
|
+
const original_message = getOriginalMessage(err);
|
|
45
|
+
// INTERNAL = infrastructure (Redis/Rabbit/etc), EXTERNAL = vendor (Stripe/etc)
|
|
46
|
+
const code = dependency.type === "INTERNAL" ? "INFRASTRUCTURE_FAILURE" : "THIRD_PARTY_ERROR";
|
|
47
|
+
const canonical = getCanonicalError(code);
|
|
48
|
+
const message = options.message ??
|
|
49
|
+
(dependency.type === "INTERNAL"
|
|
50
|
+
? `Infrastructure dependency "${dependency.name}" failed.`
|
|
51
|
+
: `Third-party provider "${dependency.name}" returned an error.`);
|
|
52
|
+
return wrapServiceError(serviceId, canonical, {
|
|
53
|
+
message,
|
|
54
|
+
dependency: { ...dependency, original_message },
|
|
55
|
+
...(options.internal_code !== undefined ? { internal_code: options.internal_code } : {}),
|
|
56
|
+
...(options.context !== undefined ? { context: options.context } : {}),
|
|
57
|
+
...(options.trace_id !== undefined ? { trace_id: options.trace_id } : {}),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export function toErrorResponse(err, options) {
|
|
61
|
+
if (isStandardError(err)) {
|
|
62
|
+
return err.toJSON();
|
|
63
|
+
}
|
|
64
|
+
const fallbackCode = options?.fallbackCode ?? "INTERNAL_ERROR";
|
|
65
|
+
const def = getErrorDefinition(fallbackCode);
|
|
66
|
+
let message = def.defaultMessage;
|
|
67
|
+
let cause = err;
|
|
68
|
+
if (err instanceof Error && typeof err.message === "string" && err.message.length > 0) {
|
|
69
|
+
message = err.message;
|
|
70
|
+
}
|
|
71
|
+
const createOptions = options?.traceId !== undefined ? { message, cause, traceId: options.traceId } : { message, cause };
|
|
72
|
+
return createErrorResponse(fallbackCode, createOptions);
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAUrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,SAAS,kBAAkB,CAAC,GAAY;IACvC,IAAI,GAAG,YAAY,KAAK,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAC1G,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,G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AAE,CAAC;QACtE,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzE,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAC9B,GAAY,EACZ,OAA4E;IAE5E,IAAI,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC;IAED,MAAM,YAAY,GAAG,OAAO,EAAE,YAAY,IAAI,gBAAgB,CAAC;IAC/D,MAAM,GAAG,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAE7C,IAAI,OAAO,GAAG,GAAG,CAAC,cAAc,CAAC;IACjC,IAAI,KAAK,GAAY,GAAG,CAAC;IAEzB,IAAI,GAAG,YAAY,KAAK,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvF,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IACvB,CAAC;IAED,MAAM,aAAa,GAClB,OAAO,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IACpG,OAAO,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ERROR_DEFINITIONS, getErrorDefinition } from "./definitions.js";
|
|
2
|
+
export { createError, createErrorResponse, getCanonicalError, handleDependencyError, toErrorResponse, wrapServiceError, } from "./factory.js";
|
|
3
|
+
export { StandardError, isStandardError } from "./standard-error.js";
|
|
4
|
+
export { ServiceId } from "./types/index.js";
|
|
5
|
+
export type { BMErrorResponse, CanonicalErrorCode, CanonicalError, CreateErrorOptions, DependencyInfo, DependencyType, ErrorContext, ErrorDefinition, StandardErrorResponse, TraceId, } from "./types/index.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,YAAY,EACX,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,OAAO,GACP,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ERROR_DEFINITIONS, getErrorDefinition } from "./definitions.js";
|
|
2
|
+
export { createError, createErrorResponse, getCanonicalError, handleDependencyError, toErrorResponse, wrapServiceError, } from "./factory.js";
|
|
3
|
+
export { StandardError, isStandardError } from "./standard-error.js";
|
|
4
|
+
export { ServiceId } from "./types/index.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CanonicalErrorCode, CreateErrorOptions, StandardErrorResponse } from "./types/index.js";
|
|
2
|
+
export declare class StandardError extends Error {
|
|
3
|
+
readonly code: CanonicalErrorCode;
|
|
4
|
+
readonly httpStatus: number;
|
|
5
|
+
readonly retryable: boolean;
|
|
6
|
+
readonly context?: Record<string, unknown>;
|
|
7
|
+
readonly traceId?: string;
|
|
8
|
+
readonly cause?: unknown;
|
|
9
|
+
constructor(code: CanonicalErrorCode, options?: CreateErrorOptions);
|
|
10
|
+
toJSON(): StandardErrorResponse;
|
|
11
|
+
}
|
|
12
|
+
export declare function isStandardError(value: unknown): value is StandardError;
|
|
13
|
+
//# sourceMappingURL=standard-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-error.d.ts","sourceRoot":"","sources":["../standard-error.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEtG,qBAAa,aAAc,SAAQ,KAAK;IACvC,SAAgB,IAAI,EAAE,kBAAkB,CAAC;IACzC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,SAAS,EAAE,OAAO,CAAC;IACnC,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,SAAgB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjC,SAAgB,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,IAAI,EAAE,kBAAkB,EAAE,OAAO,GAAE,kBAAuB;IAkBtE,MAAM,IAAI,qBAAqB;CAYtC;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getErrorDefinition } from "./definitions.js";
|
|
2
|
+
export class StandardError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
httpStatus;
|
|
5
|
+
retryable;
|
|
6
|
+
context;
|
|
7
|
+
traceId;
|
|
8
|
+
cause;
|
|
9
|
+
constructor(code, options = {}) {
|
|
10
|
+
const def = getErrorDefinition(code);
|
|
11
|
+
const message = options.message ?? def.defaultMessage;
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "StandardError";
|
|
14
|
+
this.code = def.code;
|
|
15
|
+
this.httpStatus = def.httpStatus;
|
|
16
|
+
this.retryable = def.retryable;
|
|
17
|
+
if (options.context !== undefined)
|
|
18
|
+
this.context = options.context;
|
|
19
|
+
if (options.traceId !== undefined)
|
|
20
|
+
this.traceId = options.traceId;
|
|
21
|
+
if (options.cause !== undefined)
|
|
22
|
+
this.cause = options.cause;
|
|
23
|
+
// Ensure instanceof works across TS transpilation targets.
|
|
24
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
25
|
+
}
|
|
26
|
+
toJSON() {
|
|
27
|
+
const json = {
|
|
28
|
+
error_code: this.code,
|
|
29
|
+
message: this.message,
|
|
30
|
+
status_code: this.httpStatus,
|
|
31
|
+
retryable: this.retryable,
|
|
32
|
+
...(this.context !== undefined ? { context: this.context } : {}),
|
|
33
|
+
...(this.traceId !== undefined ? { trace_id: this.traceId } : {}),
|
|
34
|
+
};
|
|
35
|
+
return json;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function isStandardError(value) {
|
|
39
|
+
return value instanceof StandardError;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=standard-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-error.js","sourceRoot":"","sources":["../standard-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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