@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type TraceId = string;
|
|
2
|
+
export type ErrorContext = Record<string, unknown>;
|
|
3
|
+
export type DependencyType = "INTERNAL" | "EXTERNAL";
|
|
4
|
+
export type DependencyInfo = Readonly<{
|
|
5
|
+
name: string;
|
|
6
|
+
type: DependencyType;
|
|
7
|
+
original_message: string;
|
|
8
|
+
}>;
|
|
9
|
+
export type CanonicalErrorCode = "INTERNAL_ERROR" | "INVALID_ARGUMENT" | "SERVICE_FAILURE" | "UI_INVALID_INPUT" | "UI_REQUIRED_FIELD_MISSING" | "UI_INVALID_FORMAT" | "UI_FILE_TOO_LARGE" | "UI_UNSUPPORTED_FILE_TYPE" | "UI_STALE_STATE" | "UI_ACTION_NOT_AVAILABLE" | "UI_DUPLICATE_SUBMISSION" | "UI_RENDER_ERROR" | "UI_ASSET_LOAD_FAILED" | "UI_TRANSLATION_MISSING" | "API_INVALID_PARAMETER" | "API_REQUIRED_PARAMETER_MISSING" | "API_INVALID_REQUEST_FORMAT" | "API_SCHEMA_VALIDATION_FAILED" | "API_TOO_MANY_ITEMS" | "API_FIELD_TOO_LONG" | "API_UNSUPPORTED_VALUE" | "AUTH_MISSING_CREDENTIALS" | "AUTH_INVALID_CREDENTIALS" | "AUTH_FORBIDDEN" | "AUTH_INSUFFICIENT_PERMISSIONS" | "AUTH_TOKEN_EXPIRED" | "DOMAIN_INCORRECT_PIN" | "DOMAIN_PIN_EXPIRED" | "DOMAIN_OTP_ATTEMPTS_EXCEEDED" | "DOMAIN_DUPLICATE_PIN" | "DOMAIN_INVALID_SCHEDULE_TIME" | "DOMAIN_RESOURCE_CONFLICT" | "DOMAIN_RESOURCE_NOT_FOUND" | "DEPENDENCY_FAILURE" | "DEPENDENCY_TIMEOUT" | "INFRASTRUCTURE_FAILURE" | "THIRD_PARTY_ERROR" | "UPSTREAM_ERROR" | "RESOURCE_EXHAUSTED" | "QUOTA_EXCEEDED" | "SERVER_OVERLOAD" | "CONCURRENCY_CONFLICT" | "ABORTED" | "OUT_OF_RANGE" | "ALREADY_EXISTS" | "NETWORK_TIMEOUT" | "PAYLOAD_TOO_LARGE" | "TOO_MANY_REQUESTS" | "CLIENT_CLOSED_REQUEST" | "GATEWAY_TIMEOUT" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE";
|
|
10
|
+
export type ErrorDefinition = Readonly<{
|
|
11
|
+
code: CanonicalErrorCode;
|
|
12
|
+
httpStatus: number;
|
|
13
|
+
retryable: boolean;
|
|
14
|
+
defaultMessage: string;
|
|
15
|
+
}>;
|
|
16
|
+
export declare enum ServiceId {
|
|
17
|
+
TwoWay = "two-way",
|
|
18
|
+
Sms = "sms",
|
|
19
|
+
Ussd = "ussd",
|
|
20
|
+
Otp = "otp",
|
|
21
|
+
Contacts = "contacts",
|
|
22
|
+
Bpay = "bpay",
|
|
23
|
+
Payments = "payments",
|
|
24
|
+
Airtime = "airtime",
|
|
25
|
+
Rewards = "rewards",
|
|
26
|
+
Booking = "booking",
|
|
27
|
+
Whatsapp = "whatsapp"
|
|
28
|
+
}
|
|
29
|
+
export type StandardErrorResponse = Readonly<{
|
|
30
|
+
error_code: CanonicalErrorCode;
|
|
31
|
+
message: string;
|
|
32
|
+
status_code: number;
|
|
33
|
+
retryable: boolean;
|
|
34
|
+
context?: ErrorContext;
|
|
35
|
+
trace_id?: TraceId;
|
|
36
|
+
}>;
|
|
37
|
+
export type CanonicalError = Readonly<Pick<StandardErrorResponse, "error_code" | "status_code" | "retryable">>;
|
|
38
|
+
export interface BMErrorResponse {
|
|
39
|
+
readonly service_id: string;
|
|
40
|
+
readonly error_code: CanonicalErrorCode;
|
|
41
|
+
readonly message: string;
|
|
42
|
+
readonly code: number;
|
|
43
|
+
readonly retryable: boolean;
|
|
44
|
+
readonly internal_code?: number | string;
|
|
45
|
+
readonly dependency?: DependencyInfo;
|
|
46
|
+
readonly context?: ErrorContext;
|
|
47
|
+
readonly trace_id?: TraceId;
|
|
48
|
+
}
|
|
49
|
+
export type CreateErrorOptions = Readonly<{
|
|
50
|
+
message?: string;
|
|
51
|
+
context?: ErrorContext;
|
|
52
|
+
traceId?: TraceId;
|
|
53
|
+
cause?: unknown;
|
|
54
|
+
}>;
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EA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AAC;CAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export var ServiceId;
|
|
2
|
+
(function (ServiceId) {
|
|
3
|
+
ServiceId["TwoWay"] = "two-way";
|
|
4
|
+
ServiceId["Sms"] = "sms";
|
|
5
|
+
ServiceId["Ussd"] = "ussd";
|
|
6
|
+
ServiceId["Otp"] = "otp";
|
|
7
|
+
ServiceId["Contacts"] = "contacts";
|
|
8
|
+
ServiceId["Bpay"] = "bpay";
|
|
9
|
+
ServiceId["Payments"] = "payments";
|
|
10
|
+
ServiceId["Airtime"] = "airtime";
|
|
11
|
+
ServiceId["Rewards"] = "rewards";
|
|
12
|
+
ServiceId["Booking"] = "booking";
|
|
13
|
+
ServiceId["Whatsapp"] = "whatsapp";
|
|
14
|
+
})(ServiceId || (ServiceId = {}));
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAoFA,MAAM,CAAN,IAAY,SAYX;AAZD,WAAY,SAAS;IACpB,+BAAkB,CAAA;IAClB,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,wBAAW,CAAA;IACX,kCAAqB,CAAA;IACrB,0BAAa,CAAA;IACb,kCAAqB,CAAA;IACrB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;AACtB,CAAC,EAZW,SAAS,KAAT,SAAS,QAYpB"}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_DEFINITIONS = void 0;
|
|
4
|
+
exports.getErrorDefinition = getErrorDefinition;
|
|
5
|
+
exports.ERROR_DEFINITIONS = {
|
|
6
|
+
INTERNAL_ERROR: {
|
|
7
|
+
code: "INTERNAL_ERROR",
|
|
8
|
+
httpStatus: 500,
|
|
9
|
+
retryable: false,
|
|
10
|
+
defaultMessage: "Unexpected server error.",
|
|
11
|
+
},
|
|
12
|
+
INVALID_ARGUMENT: {
|
|
13
|
+
code: "INVALID_ARGUMENT",
|
|
14
|
+
httpStatus: 400,
|
|
15
|
+
retryable: false,
|
|
16
|
+
defaultMessage: "Invalid argument.",
|
|
17
|
+
},
|
|
18
|
+
SERVICE_FAILURE: {
|
|
19
|
+
code: "SERVICE_FAILURE",
|
|
20
|
+
httpStatus: 500,
|
|
21
|
+
retryable: true,
|
|
22
|
+
defaultMessage: "Service failed to process the request.",
|
|
23
|
+
},
|
|
24
|
+
// UI Errors
|
|
25
|
+
UI_INVALID_INPUT: {
|
|
26
|
+
code: "UI_INVALID_INPUT",
|
|
27
|
+
httpStatus: 400,
|
|
28
|
+
retryable: false,
|
|
29
|
+
defaultMessage: "Input provided is invalid.",
|
|
30
|
+
},
|
|
31
|
+
UI_REQUIRED_FIELD_MISSING: {
|
|
32
|
+
code: "UI_REQUIRED_FIELD_MISSING",
|
|
33
|
+
httpStatus: 400,
|
|
34
|
+
retryable: false,
|
|
35
|
+
defaultMessage: "A required field is missing.",
|
|
36
|
+
},
|
|
37
|
+
UI_INVALID_FORMAT: {
|
|
38
|
+
code: "UI_INVALID_FORMAT",
|
|
39
|
+
httpStatus: 400,
|
|
40
|
+
retryable: false,
|
|
41
|
+
defaultMessage: "Input format is incorrect.",
|
|
42
|
+
},
|
|
43
|
+
UI_FILE_TOO_LARGE: {
|
|
44
|
+
code: "UI_FILE_TOO_LARGE",
|
|
45
|
+
httpStatus: 413,
|
|
46
|
+
retryable: false,
|
|
47
|
+
defaultMessage: "Uploaded file exceeds size limit.",
|
|
48
|
+
},
|
|
49
|
+
UI_UNSUPPORTED_FILE_TYPE: {
|
|
50
|
+
code: "UI_UNSUPPORTED_FILE_TYPE",
|
|
51
|
+
httpStatus: 415,
|
|
52
|
+
retryable: false,
|
|
53
|
+
defaultMessage: "File type is not supported.",
|
|
54
|
+
},
|
|
55
|
+
UI_STALE_STATE: {
|
|
56
|
+
code: "UI_STALE_STATE",
|
|
57
|
+
httpStatus: 409,
|
|
58
|
+
retryable: false,
|
|
59
|
+
defaultMessage: "UI state is outdated; refresh required.",
|
|
60
|
+
},
|
|
61
|
+
UI_ACTION_NOT_AVAILABLE: {
|
|
62
|
+
code: "UI_ACTION_NOT_AVAILABLE",
|
|
63
|
+
httpStatus: 403,
|
|
64
|
+
retryable: false,
|
|
65
|
+
defaultMessage: "Action is not allowed in current state.",
|
|
66
|
+
},
|
|
67
|
+
UI_DUPLICATE_SUBMISSION: {
|
|
68
|
+
code: "UI_DUPLICATE_SUBMISSION",
|
|
69
|
+
httpStatus: 409,
|
|
70
|
+
retryable: false,
|
|
71
|
+
defaultMessage: "Duplicate submission detected.",
|
|
72
|
+
},
|
|
73
|
+
UI_RENDER_ERROR: {
|
|
74
|
+
code: "UI_RENDER_ERROR",
|
|
75
|
+
httpStatus: 500,
|
|
76
|
+
retryable: false,
|
|
77
|
+
defaultMessage: "UI failed to render correctly.",
|
|
78
|
+
},
|
|
79
|
+
UI_ASSET_LOAD_FAILED: {
|
|
80
|
+
code: "UI_ASSET_LOAD_FAILED",
|
|
81
|
+
httpStatus: 500,
|
|
82
|
+
retryable: false,
|
|
83
|
+
defaultMessage: "Required asset failed to load.",
|
|
84
|
+
},
|
|
85
|
+
UI_TRANSLATION_MISSING: {
|
|
86
|
+
code: "UI_TRANSLATION_MISSING",
|
|
87
|
+
httpStatus: 500,
|
|
88
|
+
retryable: false,
|
|
89
|
+
defaultMessage: "Missing translation resource.",
|
|
90
|
+
},
|
|
91
|
+
// API Errors - Validation Errors
|
|
92
|
+
API_INVALID_PARAMETER: {
|
|
93
|
+
code: "API_INVALID_PARAMETER",
|
|
94
|
+
httpStatus: 400,
|
|
95
|
+
retryable: true,
|
|
96
|
+
defaultMessage: "Parameter value invalid.",
|
|
97
|
+
},
|
|
98
|
+
API_REQUIRED_PARAMETER_MISSING: {
|
|
99
|
+
code: "API_REQUIRED_PARAMETER_MISSING",
|
|
100
|
+
httpStatus: 400,
|
|
101
|
+
retryable: true,
|
|
102
|
+
defaultMessage: "Required parameter missing.",
|
|
103
|
+
},
|
|
104
|
+
API_INVALID_REQUEST_FORMAT: {
|
|
105
|
+
code: "API_INVALID_REQUEST_FORMAT",
|
|
106
|
+
httpStatus: 400,
|
|
107
|
+
retryable: true,
|
|
108
|
+
defaultMessage: "Request format is invalid.",
|
|
109
|
+
},
|
|
110
|
+
API_SCHEMA_VALIDATION_FAILED: {
|
|
111
|
+
code: "API_SCHEMA_VALIDATION_FAILED",
|
|
112
|
+
httpStatus: 400,
|
|
113
|
+
retryable: true,
|
|
114
|
+
defaultMessage: "Request schema validation failed.",
|
|
115
|
+
},
|
|
116
|
+
API_TOO_MANY_ITEMS: {
|
|
117
|
+
code: "API_TOO_MANY_ITEMS",
|
|
118
|
+
httpStatus: 429,
|
|
119
|
+
retryable: true,
|
|
120
|
+
defaultMessage: "Request contains too many items.",
|
|
121
|
+
},
|
|
122
|
+
API_FIELD_TOO_LONG: {
|
|
123
|
+
code: "API_FIELD_TOO_LONG",
|
|
124
|
+
httpStatus: 400,
|
|
125
|
+
retryable: true,
|
|
126
|
+
defaultMessage: "Field exceeds maximum length.",
|
|
127
|
+
},
|
|
128
|
+
API_UNSUPPORTED_VALUE: {
|
|
129
|
+
code: "API_UNSUPPORTED_VALUE",
|
|
130
|
+
httpStatus: 400,
|
|
131
|
+
retryable: true,
|
|
132
|
+
defaultMessage: "Parameter contains an unsupported value.",
|
|
133
|
+
},
|
|
134
|
+
// API Errors - Authentication Errors
|
|
135
|
+
AUTH_MISSING_CREDENTIALS: {
|
|
136
|
+
code: "AUTH_MISSING_CREDENTIALS",
|
|
137
|
+
httpStatus: 401,
|
|
138
|
+
retryable: true,
|
|
139
|
+
defaultMessage: "Required credentials missing.",
|
|
140
|
+
},
|
|
141
|
+
AUTH_INVALID_CREDENTIALS: {
|
|
142
|
+
code: "AUTH_INVALID_CREDENTIALS",
|
|
143
|
+
httpStatus: 401,
|
|
144
|
+
retryable: true,
|
|
145
|
+
defaultMessage: "Credentials invalid.",
|
|
146
|
+
},
|
|
147
|
+
AUTH_FORBIDDEN: {
|
|
148
|
+
code: "AUTH_FORBIDDEN",
|
|
149
|
+
httpStatus: 403,
|
|
150
|
+
retryable: true,
|
|
151
|
+
defaultMessage: "Access forbidden.",
|
|
152
|
+
},
|
|
153
|
+
AUTH_INSUFFICIENT_PERMISSIONS: {
|
|
154
|
+
code: "AUTH_INSUFFICIENT_PERMISSIONS",
|
|
155
|
+
httpStatus: 403,
|
|
156
|
+
retryable: true,
|
|
157
|
+
defaultMessage: "Not enough permissions.",
|
|
158
|
+
},
|
|
159
|
+
AUTH_TOKEN_EXPIRED: {
|
|
160
|
+
code: "AUTH_TOKEN_EXPIRED",
|
|
161
|
+
httpStatus: 401,
|
|
162
|
+
retryable: true,
|
|
163
|
+
defaultMessage: "Auth token expired.",
|
|
164
|
+
},
|
|
165
|
+
// API Errors - Business Logic Errors
|
|
166
|
+
DOMAIN_INCORRECT_PIN: {
|
|
167
|
+
code: "DOMAIN_INCORRECT_PIN",
|
|
168
|
+
httpStatus: 400,
|
|
169
|
+
retryable: true,
|
|
170
|
+
defaultMessage: "OTP Pin is incorrect.",
|
|
171
|
+
},
|
|
172
|
+
DOMAIN_PIN_EXPIRED: {
|
|
173
|
+
code: "DOMAIN_PIN_EXPIRED",
|
|
174
|
+
httpStatus: 400,
|
|
175
|
+
retryable: true,
|
|
176
|
+
defaultMessage: "OTP Pin expired.",
|
|
177
|
+
},
|
|
178
|
+
DOMAIN_OTP_ATTEMPTS_EXCEEDED: {
|
|
179
|
+
code: "DOMAIN_OTP_ATTEMPTS_EXCEEDED",
|
|
180
|
+
httpStatus: 429,
|
|
181
|
+
retryable: true,
|
|
182
|
+
defaultMessage: "OTP attempts exceeded.",
|
|
183
|
+
},
|
|
184
|
+
DOMAIN_DUPLICATE_PIN: {
|
|
185
|
+
code: "DOMAIN_DUPLICATE_PIN",
|
|
186
|
+
httpStatus: 409,
|
|
187
|
+
retryable: true,
|
|
188
|
+
defaultMessage: "OTP Pin already used.",
|
|
189
|
+
},
|
|
190
|
+
DOMAIN_INVALID_SCHEDULE_TIME: {
|
|
191
|
+
code: "DOMAIN_INVALID_SCHEDULE_TIME",
|
|
192
|
+
httpStatus: 400,
|
|
193
|
+
retryable: true,
|
|
194
|
+
defaultMessage: "Scheduled time invalid.",
|
|
195
|
+
},
|
|
196
|
+
DOMAIN_RESOURCE_CONFLICT: {
|
|
197
|
+
code: "DOMAIN_RESOURCE_CONFLICT",
|
|
198
|
+
httpStatus: 409,
|
|
199
|
+
retryable: true,
|
|
200
|
+
defaultMessage: "Resource conflict detected.",
|
|
201
|
+
},
|
|
202
|
+
DOMAIN_RESOURCE_NOT_FOUND: {
|
|
203
|
+
code: "DOMAIN_RESOURCE_NOT_FOUND",
|
|
204
|
+
httpStatus: 404,
|
|
205
|
+
retryable: true,
|
|
206
|
+
defaultMessage: "Resource not found.",
|
|
207
|
+
},
|
|
208
|
+
// API Errors - Dependency & Integration Errors
|
|
209
|
+
DEPENDENCY_FAILURE: {
|
|
210
|
+
code: "DEPENDENCY_FAILURE",
|
|
211
|
+
httpStatus: 502,
|
|
212
|
+
retryable: true,
|
|
213
|
+
defaultMessage: "A required downstream service is down.",
|
|
214
|
+
},
|
|
215
|
+
DEPENDENCY_TIMEOUT: {
|
|
216
|
+
code: "DEPENDENCY_TIMEOUT",
|
|
217
|
+
httpStatus: 504,
|
|
218
|
+
retryable: true,
|
|
219
|
+
defaultMessage: "Downstream service responded too slowly.",
|
|
220
|
+
},
|
|
221
|
+
INFRASTRUCTURE_FAILURE: {
|
|
222
|
+
code: "INFRASTRUCTURE_FAILURE",
|
|
223
|
+
httpStatus: 503,
|
|
224
|
+
retryable: true,
|
|
225
|
+
defaultMessage: "An internal infrastructure dependency failed.",
|
|
226
|
+
},
|
|
227
|
+
THIRD_PARTY_ERROR: {
|
|
228
|
+
code: "THIRD_PARTY_ERROR",
|
|
229
|
+
httpStatus: 502,
|
|
230
|
+
retryable: true,
|
|
231
|
+
defaultMessage: "A third-party provider returned an error.",
|
|
232
|
+
},
|
|
233
|
+
UPSTREAM_ERROR: {
|
|
234
|
+
code: "UPSTREAM_ERROR",
|
|
235
|
+
httpStatus: 502,
|
|
236
|
+
retryable: false,
|
|
237
|
+
defaultMessage: "Downstream service returned an invalid response.",
|
|
238
|
+
},
|
|
239
|
+
// API Errors - Rate Limiting Errors
|
|
240
|
+
RESOURCE_EXHAUSTED: {
|
|
241
|
+
code: "RESOURCE_EXHAUSTED",
|
|
242
|
+
httpStatus: 429,
|
|
243
|
+
retryable: true,
|
|
244
|
+
defaultMessage: "User has hit their rate limit.",
|
|
245
|
+
},
|
|
246
|
+
QUOTA_EXCEEDED: {
|
|
247
|
+
code: "QUOTA_EXCEEDED",
|
|
248
|
+
httpStatus: 403,
|
|
249
|
+
retryable: false,
|
|
250
|
+
defaultMessage: "Monthly billing limit reached.",
|
|
251
|
+
},
|
|
252
|
+
SERVER_OVERLOAD: {
|
|
253
|
+
code: "SERVER_OVERLOAD",
|
|
254
|
+
httpStatus: 503,
|
|
255
|
+
retryable: true,
|
|
256
|
+
defaultMessage: "System is too busy to handle the request; back off immediately.",
|
|
257
|
+
},
|
|
258
|
+
// API Errors - Concurrency & State Errors
|
|
259
|
+
CONCURRENCY_CONFLICT: {
|
|
260
|
+
code: "CONCURRENCY_CONFLICT",
|
|
261
|
+
httpStatus: 409,
|
|
262
|
+
retryable: true,
|
|
263
|
+
defaultMessage: "Conflict detected. Please refresh and try again.",
|
|
264
|
+
},
|
|
265
|
+
ABORTED: {
|
|
266
|
+
code: "ABORTED",
|
|
267
|
+
httpStatus: 409,
|
|
268
|
+
retryable: true,
|
|
269
|
+
defaultMessage: "Conflict detected.",
|
|
270
|
+
},
|
|
271
|
+
OUT_OF_RANGE: {
|
|
272
|
+
code: "OUT_OF_RANGE",
|
|
273
|
+
httpStatus: 400,
|
|
274
|
+
retryable: false,
|
|
275
|
+
defaultMessage: "Client navigated beyond the valid state.",
|
|
276
|
+
},
|
|
277
|
+
ALREADY_EXISTS: {
|
|
278
|
+
code: "ALREADY_EXISTS",
|
|
279
|
+
httpStatus: 409,
|
|
280
|
+
retryable: false,
|
|
281
|
+
defaultMessage: "Resource already exists.",
|
|
282
|
+
},
|
|
283
|
+
// API Errors - Network Errors
|
|
284
|
+
NETWORK_TIMEOUT: {
|
|
285
|
+
code: "NETWORK_TIMEOUT",
|
|
286
|
+
httpStatus: 408,
|
|
287
|
+
retryable: true,
|
|
288
|
+
defaultMessage: "The client started a request but did not finish sending it in time.",
|
|
289
|
+
},
|
|
290
|
+
PAYLOAD_TOO_LARGE: {
|
|
291
|
+
code: "PAYLOAD_TOO_LARGE",
|
|
292
|
+
httpStatus: 413,
|
|
293
|
+
retryable: false,
|
|
294
|
+
defaultMessage: "The request body exceeds the network limit.",
|
|
295
|
+
},
|
|
296
|
+
TOO_MANY_REQUESTS: {
|
|
297
|
+
code: "TOO_MANY_REQUESTS",
|
|
298
|
+
httpStatus: 429,
|
|
299
|
+
retryable: true,
|
|
300
|
+
defaultMessage: "Network-level rate limiter blocked the request.",
|
|
301
|
+
},
|
|
302
|
+
CLIENT_CLOSED_REQUEST: {
|
|
303
|
+
code: "CLIENT_CLOSED_REQUEST",
|
|
304
|
+
httpStatus: 499,
|
|
305
|
+
retryable: false,
|
|
306
|
+
defaultMessage: "Client cancelled the request before the server finished.",
|
|
307
|
+
},
|
|
308
|
+
// API Errors - Server-Side Infrastructure Errors
|
|
309
|
+
GATEWAY_TIMEOUT: {
|
|
310
|
+
code: "GATEWAY_TIMEOUT",
|
|
311
|
+
httpStatus: 504,
|
|
312
|
+
retryable: true,
|
|
313
|
+
defaultMessage: "API gateway timed out waiting for upstream service.",
|
|
314
|
+
},
|
|
315
|
+
BAD_GATEWAY: {
|
|
316
|
+
code: "BAD_GATEWAY",
|
|
317
|
+
httpStatus: 502,
|
|
318
|
+
retryable: true,
|
|
319
|
+
defaultMessage: "Server received an invalid response from upstream.",
|
|
320
|
+
},
|
|
321
|
+
SERVICE_UNAVAILABLE: {
|
|
322
|
+
code: "SERVICE_UNAVAILABLE",
|
|
323
|
+
httpStatus: 503,
|
|
324
|
+
retryable: true,
|
|
325
|
+
defaultMessage: "Service unavailable.",
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
function getErrorDefinition(code) {
|
|
329
|
+
return exports.ERROR_DEFINITIONS[code];
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../definitions.ts"],"names":[],"mappings":";;;AA+UA,gDAEC;AA/UY,QAAA,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,E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AAK;QAChB,cAAc,EAAE,0BAA0B;KAC1C;IAED,8BAA8B;IAC9B,eAAe,EAAE;QAChB,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,IAAI;QACf,cAAc,EAAE,qEAAqE;KACrF;IACD,iBAAiB,EAAE;QAClB,IAAI,EAAE,mBAAmB;QACzB,UAAU,EAAE,GAAG;QACf,SAAS,EAAE,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,SAAgB,kBAAkB,CAAC,IAAwB;IAC1D,OAAO,yBAAiB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createError = createError;
|
|
4
|
+
exports.getCanonicalError = getCanonicalError;
|
|
5
|
+
exports.createErrorResponse = createErrorResponse;
|
|
6
|
+
exports.wrapServiceError = wrapServiceError;
|
|
7
|
+
exports.handleDependencyError = handleDependencyError;
|
|
8
|
+
exports.toErrorResponse = toErrorResponse;
|
|
9
|
+
const definitions_js_1 = require("./definitions.js");
|
|
10
|
+
const standard_error_js_1 = require("./standard-error.js");
|
|
11
|
+
function getOriginalMessage(err) {
|
|
12
|
+
if (err instanceof Error && typeof err.message === "string" && err.message.length > 0)
|
|
13
|
+
return err.message;
|
|
14
|
+
if (typeof err === "string" && err.length > 0)
|
|
15
|
+
return err;
|
|
16
|
+
try {
|
|
17
|
+
return JSON.stringify(err);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return "Unknown dependency error.";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function createError(code, options = {}) {
|
|
24
|
+
return new standard_error_js_1.StandardError(code, options);
|
|
25
|
+
}
|
|
26
|
+
function getCanonicalError(code) {
|
|
27
|
+
const def = (0, definitions_js_1.getErrorDefinition)(code);
|
|
28
|
+
return {
|
|
29
|
+
error_code: def.code,
|
|
30
|
+
status_code: def.httpStatus,
|
|
31
|
+
retryable: def.retryable,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function createErrorResponse(code, options = {}) {
|
|
35
|
+
return createError(code, options).toJSON();
|
|
36
|
+
}
|
|
37
|
+
function wrapServiceError(serviceId, baseError, overrides) {
|
|
38
|
+
return {
|
|
39
|
+
service_id: serviceId,
|
|
40
|
+
error_code: baseError.error_code,
|
|
41
|
+
message: overrides.message,
|
|
42
|
+
code: baseError.status_code,
|
|
43
|
+
retryable: baseError.retryable,
|
|
44
|
+
...(overrides.internal_code !== undefined ? { internal_code: overrides.internal_code } : {}),
|
|
45
|
+
...(overrides.dependency !== undefined ? { dependency: overrides.dependency } : {}),
|
|
46
|
+
...(overrides.context !== undefined ? { context: overrides.context } : {}),
|
|
47
|
+
...(overrides.trace_id !== undefined ? { trace_id: overrides.trace_id } : {}),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function handleDependencyError(serviceId, dependency, err, options = {}) {
|
|
51
|
+
const original_message = getOriginalMessage(err);
|
|
52
|
+
// INTERNAL = infrastructure (Redis/Rabbit/etc), EXTERNAL = vendor (Stripe/etc)
|
|
53
|
+
const code = dependency.type === "INTERNAL" ? "INFRASTRUCTURE_FAILURE" : "THIRD_PARTY_ERROR";
|
|
54
|
+
const canonical = getCanonicalError(code);
|
|
55
|
+
const message = options.message ??
|
|
56
|
+
(dependency.type === "INTERNAL"
|
|
57
|
+
? `Infrastructure dependency "${dependency.name}" failed.`
|
|
58
|
+
: `Third-party provider "${dependency.name}" returned an error.`);
|
|
59
|
+
return wrapServiceError(serviceId, canonical, {
|
|
60
|
+
message,
|
|
61
|
+
dependency: { ...dependency, original_message },
|
|
62
|
+
...(options.internal_code !== undefined ? { internal_code: options.internal_code } : {}),
|
|
63
|
+
...(options.context !== undefined ? { context: options.context } : {}),
|
|
64
|
+
...(options.trace_id !== undefined ? { trace_id: options.trace_id } : {}),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function toErrorResponse(err, options) {
|
|
68
|
+
if ((0, standard_error_js_1.isStandardError)(err)) {
|
|
69
|
+
return err.toJSON();
|
|
70
|
+
}
|
|
71
|
+
const fallbackCode = options?.fallbackCode ?? "INTERNAL_ERROR";
|
|
72
|
+
const def = (0, definitions_js_1.getErrorDefinition)(fallbackCode);
|
|
73
|
+
let message = def.defaultMessage;
|
|
74
|
+
let cause = err;
|
|
75
|
+
if (err instanceof Error && typeof err.message === "string" && err.message.length > 0) {
|
|
76
|
+
message = err.message;
|
|
77
|
+
}
|
|
78
|
+
const createOptions = options?.traceId !== undefined ? { message, cause, traceId: options.traceId } : { message, cause };
|
|
79
|
+
return createErrorResponse(fallbackCode, createOptions);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../factory.ts"],"names":[],"m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E,OAAO,EAAE,KAAK,EAAE,CAAC;IACpG,OAAO,mBAAmB,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceId = exports.isStandardError = exports.StandardError = exports.wrapServiceError = exports.toErrorResponse = exports.handleDependencyError = exports.getCanonicalError = exports.createErrorResponse = exports.createError = exports.getErrorDefinition = exports.ERROR_DEFINITIONS = void 0;
|
|
4
|
+
var definitions_js_1 = require("./definitions.js");
|
|
5
|
+
Object.defineProperty(exports, "ERROR_DEFINITIONS", { enumerable: true, get: function () { return definitions_js_1.ERROR_DEFINITIONS; } });
|
|
6
|
+
Object.defineProperty(exports, "getErrorDefinition", { enumerable: true, get: function () { return definitions_js_1.getErrorDefinition; } });
|
|
7
|
+
var factory_js_1 = require("./factory.js");
|
|
8
|
+
Object.defineProperty(exports, "createError", { enumerable: true, get: function () { return factory_js_1.createError; } });
|
|
9
|
+
Object.defineProperty(exports, "createErrorResponse", { enumerable: true, get: function () { return factory_js_1.createErrorResponse; } });
|
|
10
|
+
Object.defineProperty(exports, "getCanonicalError", { enumerable: true, get: function () { return factory_js_1.getCanonicalError; } });
|
|
11
|
+
Object.defineProperty(exports, "handleDependencyError", { enumerable: true, get: function () { return factory_js_1.handleDependencyError; } });
|
|
12
|
+
Object.defineProperty(exports, "toErrorResponse", { enumerable: true, get: function () { return factory_js_1.toErrorResponse; } });
|
|
13
|
+
Object.defineProperty(exports, "wrapServiceError", { enumerable: true, get: function () { return factory_js_1.wrapServiceError; } });
|
|
14
|
+
var standard_error_js_1 = require("./standard-error.js");
|
|
15
|
+
Object.defineProperty(exports, "StandardError", { enumerable: true, get: function () { return standard_error_js_1.StandardError; } });
|
|
16
|
+
Object.defineProperty(exports, "isStandardError", { enumerable: true, get: function () { return standard_error_js_1.isStandardError; } });
|
|
17
|
+
var index_js_1 = require("./types/index.js");
|
|
18
|
+
Object.defineProperty(exports, "ServiceId", { enumerable: true, get: function () { return index_js_1.ServiceId; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,mDAAyE;AAAhE,mHAAA,iBAAiB,OAAA;AAAE,oHAAA,kBAAkB,OAAA;AAC9C,2CAOsB;AANrB,yGAAA,WAAW,OAAA;AACX,iHAAA,mBAAmB,OAAA;AACnB,+GAAA,iBAAiB,OAAA;AACjB,mHAAA,qBAAqB,OAAA;AACrB,6GAAA,eAAe,OAAA;AACf,8GAAA,gBAAgB,OAAA;AAEjB,yDAAqE;AAA5D,kHAAA,aAAa,OAAA;AAAE,oHAAA,eAAe,OAAA;AACvC,6CAA6C;AAApC,qGAAA,SAAS,OAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StandardError = void 0;
|
|
4
|
+
exports.isStandardError = isStandardError;
|
|
5
|
+
const definitions_js_1 = require("./definitions.js");
|
|
6
|
+
class StandardError extends Error {
|
|
7
|
+
code;
|
|
8
|
+
httpStatus;
|
|
9
|
+
retryable;
|
|
10
|
+
context;
|
|
11
|
+
traceId;
|
|
12
|
+
cause;
|
|
13
|
+
constructor(code, options = {}) {
|
|
14
|
+
const def = (0, definitions_js_1.getErrorDefinition)(code);
|
|
15
|
+
const message = options.message ?? def.defaultMessage;
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "StandardError";
|
|
18
|
+
this.code = def.code;
|
|
19
|
+
this.httpStatus = def.httpStatus;
|
|
20
|
+
this.retryable = def.retryable;
|
|
21
|
+
if (options.context !== undefined)
|
|
22
|
+
this.context = options.context;
|
|
23
|
+
if (options.traceId !== undefined)
|
|
24
|
+
this.traceId = options.traceId;
|
|
25
|
+
if (options.cause !== undefined)
|
|
26
|
+
this.cause = options.cause;
|
|
27
|
+
// Ensure instanceof works across TS transpilation targets.
|
|
28
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
29
|
+
}
|
|
30
|
+
toJSON() {
|
|
31
|
+
const json = {
|
|
32
|
+
error_code: this.code,
|
|
33
|
+
message: this.message,
|
|
34
|
+
status_code: this.httpStatus,
|
|
35
|
+
retryable: this.retryable,
|
|
36
|
+
...(this.context !== undefined ? { context: this.context } : {}),
|
|
37
|
+
...(this.traceId !== undefined ? { trace_id: this.traceId } : {}),
|
|
38
|
+
};
|
|
39
|
+
return json;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.StandardError = StandardError;
|
|
43
|
+
function isStandardError(value) {
|
|
44
|
+
return value instanceof StandardError;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=standard-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard-error.js","sourceRoot":"","sources":["../standard-error.ts"],"names":[],"mappings":";;;AA2CA,0CAEC;AA7CD,qDAAsD;AAGtD,MAAa,aAAc,SAAQ,KAAK;IACvB,IAAI,CAAqB;IACzB,UAAU,CAAS;IACnB,SAAS,CAAU;IACnB,OAAO,CAA2B;IAClC,OAAO,CAAU;IACjB,KAAK,CAAW;IAEhC,YAAmB,IAAwB,EAAE,UAA8B,EAAE;QAC5E,MAAM,GAAG,GAAG,IAAA,mCAAkB,EAAC,IAAI,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC,cAAc,CAAC;QAEtD,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAClE,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAClE,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAE5D,2DAA2D;QAC3D,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACnD,CAAC;IAEM,MAAM;QACZ,MAAM,IAAI,GAA0B;YACnC,UAAU,EAAE,IAAI,CAAC,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,WAAW,EAAE,IAAI,CAAC,UAAU;YAC5B,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAChE,GAAG,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjE,CAAC;QAEF,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAtCD,sCAsCC;AAED,SAAgB,eAAe,CAAC,KAAc;IAC7C,OAAO,KAAK,YAAY,aAAa,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ServiceId = void 0;
|
|
4
|
+
var ServiceId;
|
|
5
|
+
(function (ServiceId) {
|
|
6
|
+
ServiceId["TwoWay"] = "two-way";
|
|
7
|
+
ServiceId["Sms"] = "sms";
|
|
8
|
+
ServiceId["Ussd"] = "ussd";
|
|
9
|
+
ServiceId["Otp"] = "otp";
|
|
10
|
+
ServiceId["Contacts"] = "contacts";
|
|
11
|
+
ServiceId["Bpay"] = "bpay";
|
|
12
|
+
ServiceId["Payments"] = "payments";
|
|
13
|
+
ServiceId["Airtime"] = "airtime";
|
|
14
|
+
ServiceId["Rewards"] = "rewards";
|
|
15
|
+
ServiceId["Booking"] = "booking";
|
|
16
|
+
ServiceId["Whatsapp"] = "whatsapp";
|
|
17
|
+
})(ServiceId || (exports.ServiceId = ServiceId = {}));
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":";;;AAoFA,IAAY,SAYX;AAZD,WAAY,SAAS;IACpB,+BAAkB,CAAA;IAClB,wBAAW,CAAA;IACX,0BAAa,CAAA;IACb,wBAAW,CAAA;IACX,kCAAqB,CAAA;IACrB,0BAAa,CAAA;IACb,kCAAqB,CAAA;IACrB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,gCAAmB,CAAA;IACnB,kCAAqB,CAAA;AACtB,CAAC,EAZW,SAAS,yBAAT,SAAS,QAYpB"}
|