http-response-kit 1.0.0 → 2.0.0
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/LICENSE +21 -21
- package/README.md +357 -272
- package/dist/chunk-373JVXMN.mjs +1199 -0
- package/dist/chunk-373JVXMN.mjs.map +1 -0
- package/dist/chunk-FFRB2EUE.mjs +36 -0
- package/dist/chunk-FFRB2EUE.mjs.map +1 -0
- package/dist/express.d.mts +50 -0
- package/dist/express.d.ts +50 -0
- package/dist/express.js +1155 -0
- package/dist/express.js.map +1 -0
- package/dist/express.mjs +28 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +45 -0
- package/dist/fastify.d.ts +45 -0
- package/dist/fastify.js +1170 -0
- package/dist/fastify.js.map +1 -0
- package/dist/fastify.mjs +43 -0
- package/dist/fastify.mjs.map +1 -0
- package/dist/hono.d.mts +33 -0
- package/dist/hono.d.ts +33 -0
- package/dist/hono.js +1139 -0
- package/dist/hono.js.map +1 -0
- package/dist/hono.mjs +18 -0
- package/dist/hono.mjs.map +1 -0
- package/dist/index.d.mts +75 -493
- package/dist/index.d.ts +75 -493
- package/dist/index.js +480 -180
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +18 -891
- package/dist/index.mjs.map +1 -0
- package/dist/kit-nHfihlKE.d.mts +753 -0
- package/dist/kit-nHfihlKE.d.ts +753 -0
- package/dist/koa.d.mts +38 -0
- package/dist/koa.d.ts +38 -0
- package/dist/koa.js +1150 -0
- package/dist/koa.js.map +1 -0
- package/dist/koa.mjs +24 -0
- package/dist/koa.mjs.map +1 -0
- package/dist/schemas.d.mts +452 -0
- package/dist/schemas.d.ts +452 -0
- package/dist/schemas.js +124 -0
- package/dist/schemas.js.map +1 -0
- package/dist/schemas.mjs +119 -0
- package/dist/schemas.mjs.map +1 -0
- package/dist/shared-Czwmz6Xa.d.ts +22 -0
- package/dist/shared-DYq1Fic4.d.mts +22 -0
- package/package.json +104 -49
package/dist/index.mjs
CHANGED
|
@@ -1,895 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
HttpClientErrorCode2[HttpClientErrorCode2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
4
|
-
HttpClientErrorCode2[HttpClientErrorCode2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
5
|
-
HttpClientErrorCode2[HttpClientErrorCode2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
6
|
-
HttpClientErrorCode2[HttpClientErrorCode2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
7
|
-
HttpClientErrorCode2[HttpClientErrorCode2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
8
|
-
HttpClientErrorCode2[HttpClientErrorCode2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
9
|
-
HttpClientErrorCode2[HttpClientErrorCode2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
10
|
-
HttpClientErrorCode2[HttpClientErrorCode2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
11
|
-
HttpClientErrorCode2[HttpClientErrorCode2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
12
|
-
HttpClientErrorCode2[HttpClientErrorCode2["CONFLICT"] = 409] = "CONFLICT";
|
|
13
|
-
HttpClientErrorCode2[HttpClientErrorCode2["GONE"] = 410] = "GONE";
|
|
14
|
-
HttpClientErrorCode2[HttpClientErrorCode2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
15
|
-
HttpClientErrorCode2[HttpClientErrorCode2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
16
|
-
HttpClientErrorCode2[HttpClientErrorCode2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
|
|
17
|
-
HttpClientErrorCode2[HttpClientErrorCode2["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
|
|
18
|
-
HttpClientErrorCode2[HttpClientErrorCode2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
19
|
-
HttpClientErrorCode2[HttpClientErrorCode2["RANGE_NOT_SATISFIABLE"] = 416] = "RANGE_NOT_SATISFIABLE";
|
|
20
|
-
HttpClientErrorCode2[HttpClientErrorCode2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
21
|
-
HttpClientErrorCode2[HttpClientErrorCode2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
22
|
-
HttpClientErrorCode2[HttpClientErrorCode2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
23
|
-
HttpClientErrorCode2[HttpClientErrorCode2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
24
|
-
HttpClientErrorCode2[HttpClientErrorCode2["LOCKED"] = 423] = "LOCKED";
|
|
25
|
-
HttpClientErrorCode2[HttpClientErrorCode2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
26
|
-
HttpClientErrorCode2[HttpClientErrorCode2["TOO_EARLY"] = 425] = "TOO_EARLY";
|
|
27
|
-
HttpClientErrorCode2[HttpClientErrorCode2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
|
|
28
|
-
HttpClientErrorCode2[HttpClientErrorCode2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
29
|
-
HttpClientErrorCode2[HttpClientErrorCode2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
30
|
-
HttpClientErrorCode2[HttpClientErrorCode2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
31
|
-
HttpClientErrorCode2[HttpClientErrorCode2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
32
|
-
return HttpClientErrorCode2;
|
|
33
|
-
})(HttpClientErrorCode || {});
|
|
34
|
-
var HttpServerErrorCode = /* @__PURE__ */ ((HttpServerErrorCode2) => {
|
|
35
|
-
HttpServerErrorCode2[HttpServerErrorCode2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
36
|
-
HttpServerErrorCode2[HttpServerErrorCode2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
37
|
-
HttpServerErrorCode2[HttpServerErrorCode2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
38
|
-
HttpServerErrorCode2[HttpServerErrorCode2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
39
|
-
HttpServerErrorCode2[HttpServerErrorCode2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
40
|
-
HttpServerErrorCode2[HttpServerErrorCode2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
41
|
-
HttpServerErrorCode2[HttpServerErrorCode2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
|
|
42
|
-
HttpServerErrorCode2[HttpServerErrorCode2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
43
|
-
HttpServerErrorCode2[HttpServerErrorCode2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
|
|
44
|
-
HttpServerErrorCode2[HttpServerErrorCode2["BANDWIDTH_LIMIT_EXCEEDED"] = 509] = "BANDWIDTH_LIMIT_EXCEEDED";
|
|
45
|
-
HttpServerErrorCode2[HttpServerErrorCode2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
|
|
46
|
-
HttpServerErrorCode2[HttpServerErrorCode2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
47
|
-
return HttpServerErrorCode2;
|
|
48
|
-
})(HttpServerErrorCode || {});
|
|
49
|
-
var HttpErrorCode = {
|
|
50
|
-
...HttpClientErrorCode,
|
|
51
|
-
...HttpServerErrorCode
|
|
52
|
-
};
|
|
53
|
-
var HttpSuccessCode = /* @__PURE__ */ ((HttpSuccessCode2) => {
|
|
54
|
-
HttpSuccessCode2[HttpSuccessCode2["OK"] = 200] = "OK";
|
|
55
|
-
HttpSuccessCode2[HttpSuccessCode2["CREATED"] = 201] = "CREATED";
|
|
56
|
-
HttpSuccessCode2[HttpSuccessCode2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
57
|
-
HttpSuccessCode2[HttpSuccessCode2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
58
|
-
HttpSuccessCode2[HttpSuccessCode2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
59
|
-
HttpSuccessCode2[HttpSuccessCode2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
60
|
-
HttpSuccessCode2[HttpSuccessCode2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
61
|
-
HttpSuccessCode2[HttpSuccessCode2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
62
|
-
HttpSuccessCode2[HttpSuccessCode2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
|
|
63
|
-
HttpSuccessCode2[HttpSuccessCode2["IM_USED"] = 226] = "IM_USED";
|
|
64
|
-
return HttpSuccessCode2;
|
|
65
|
-
})(HttpSuccessCode || {});
|
|
66
|
-
var HttpRedirectCode = /* @__PURE__ */ ((HttpRedirectCode2) => {
|
|
67
|
-
HttpRedirectCode2[HttpRedirectCode2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
68
|
-
HttpRedirectCode2[HttpRedirectCode2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
69
|
-
HttpRedirectCode2[HttpRedirectCode2["FOUND"] = 302] = "FOUND";
|
|
70
|
-
HttpRedirectCode2[HttpRedirectCode2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
71
|
-
HttpRedirectCode2[HttpRedirectCode2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
72
|
-
HttpRedirectCode2[HttpRedirectCode2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
73
|
-
HttpRedirectCode2[HttpRedirectCode2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
74
|
-
HttpRedirectCode2[HttpRedirectCode2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
75
|
-
return HttpRedirectCode2;
|
|
76
|
-
})(HttpRedirectCode || {});
|
|
77
|
-
var HttpInfoCode = /* @__PURE__ */ ((HttpInfoCode2) => {
|
|
78
|
-
HttpInfoCode2[HttpInfoCode2["CONTINUE"] = 100] = "CONTINUE";
|
|
79
|
-
HttpInfoCode2[HttpInfoCode2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
80
|
-
HttpInfoCode2[HttpInfoCode2["PROCESSING"] = 102] = "PROCESSING";
|
|
81
|
-
HttpInfoCode2[HttpInfoCode2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
|
|
82
|
-
return HttpInfoCode2;
|
|
83
|
-
})(HttpInfoCode || {});
|
|
1
|
+
import { HttpError } from './chunk-373JVXMN.mjs';
|
|
2
|
+
export { HttpClientErrorCode, HttpError, HttpErrorCode, HttpErrorDefinitions, HttpInfoCode, HttpInfoDefinitions, HttpRedirectCode, HttpRedirectDefinitions, HttpServerErrorCode, HttpSuccessCode, HttpSuccessDefinitions, PROBLEM_CONTENT_TYPE, ResponseKit, SystemErrorStatusMap, createResponseKit, getErrorDefinition, getSuccessDefinition, isErrorResponse, isProblemDetails, isSuccessResponse, mapSystemError, toProblem } from './chunk-373JVXMN.mjs';
|
|
84
3
|
|
|
85
|
-
// src/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
[401 /* UNAUTHORIZED */]: {
|
|
97
|
-
type: "unauthorized",
|
|
98
|
-
title: "Unauthorized",
|
|
99
|
-
code: 401,
|
|
100
|
-
details: "Authentication is required and has failed or not yet been provided."
|
|
101
|
-
},
|
|
102
|
-
[402 /* PAYMENT_REQUIRED */]: {
|
|
103
|
-
type: "payment_required",
|
|
104
|
-
title: "Payment Required",
|
|
105
|
-
code: 402,
|
|
106
|
-
details: "Payment is required to access this resource."
|
|
107
|
-
},
|
|
108
|
-
[403 /* FORBIDDEN */]: {
|
|
109
|
-
type: "forbidden",
|
|
110
|
-
title: "Forbidden",
|
|
111
|
-
code: 403,
|
|
112
|
-
details: "The server understood the request but refuses to authorize it."
|
|
113
|
-
},
|
|
114
|
-
[404 /* NOT_FOUND */]: {
|
|
115
|
-
type: "not_found",
|
|
116
|
-
title: "Not Found",
|
|
117
|
-
code: 404,
|
|
118
|
-
details: "The requested resource could not be found."
|
|
119
|
-
},
|
|
120
|
-
[405 /* METHOD_NOT_ALLOWED */]: {
|
|
121
|
-
type: "method_not_allowed",
|
|
122
|
-
title: "Method Not Allowed",
|
|
123
|
-
code: 405,
|
|
124
|
-
details: "The method specified in the request is not allowed for the resource."
|
|
125
|
-
},
|
|
126
|
-
[406 /* NOT_ACCEPTABLE */]: {
|
|
127
|
-
type: "not_acceptable",
|
|
128
|
-
title: "Not Acceptable",
|
|
129
|
-
code: 406,
|
|
130
|
-
details: "The resource is not available in a format acceptable to the client."
|
|
131
|
-
},
|
|
132
|
-
[407 /* PROXY_AUTHENTICATION_REQUIRED */]: {
|
|
133
|
-
type: "proxy_authentication_required",
|
|
134
|
-
title: "Proxy Authentication Required",
|
|
135
|
-
code: 407,
|
|
136
|
-
details: "Authentication with the proxy is required."
|
|
137
|
-
},
|
|
138
|
-
[408 /* REQUEST_TIMEOUT */]: {
|
|
139
|
-
type: "request_timeout",
|
|
140
|
-
title: "Request Timeout",
|
|
141
|
-
code: 408,
|
|
142
|
-
details: "The server timed out waiting for the request."
|
|
143
|
-
},
|
|
144
|
-
[409 /* CONFLICT */]: {
|
|
145
|
-
type: "conflict",
|
|
146
|
-
title: "Conflict",
|
|
147
|
-
code: 409,
|
|
148
|
-
details: "The request conflicts with the current state of the resource."
|
|
149
|
-
},
|
|
150
|
-
[410 /* GONE */]: {
|
|
151
|
-
type: "gone",
|
|
152
|
-
title: "Gone",
|
|
153
|
-
code: 410,
|
|
154
|
-
details: "The requested resource is no longer available and will not be available again."
|
|
155
|
-
},
|
|
156
|
-
[411 /* LENGTH_REQUIRED */]: {
|
|
157
|
-
type: "length_required",
|
|
158
|
-
title: "Length Required",
|
|
159
|
-
code: 411,
|
|
160
|
-
details: "The request did not specify the length of its content, which is required."
|
|
161
|
-
},
|
|
162
|
-
[412 /* PRECONDITION_FAILED */]: {
|
|
163
|
-
type: "precondition_failed",
|
|
164
|
-
title: "Precondition Failed",
|
|
165
|
-
code: 412,
|
|
166
|
-
details: "One or more conditions in the request header fields evaluated to false."
|
|
167
|
-
},
|
|
168
|
-
[413 /* PAYLOAD_TOO_LARGE */]: {
|
|
169
|
-
type: "payload_too_large",
|
|
170
|
-
title: "Payload Too Large",
|
|
171
|
-
code: 413,
|
|
172
|
-
details: "The request payload is larger than the server is willing to process."
|
|
173
|
-
},
|
|
174
|
-
[414 /* URI_TOO_LONG */]: {
|
|
175
|
-
type: "uri_too_long",
|
|
176
|
-
title: "URI Too Long",
|
|
177
|
-
code: 414,
|
|
178
|
-
details: "The URI provided was too long for the server to process."
|
|
179
|
-
},
|
|
180
|
-
[415 /* UNSUPPORTED_MEDIA_TYPE */]: {
|
|
181
|
-
type: "unsupported_media_type",
|
|
182
|
-
title: "Unsupported Media Type",
|
|
183
|
-
code: 415,
|
|
184
|
-
details: "The media format of the requested data is not supported by the server."
|
|
185
|
-
},
|
|
186
|
-
[416 /* RANGE_NOT_SATISFIABLE */]: {
|
|
187
|
-
type: "range_not_satisfiable",
|
|
188
|
-
title: "Range Not Satisfiable",
|
|
189
|
-
code: 416,
|
|
190
|
-
details: "The range specified in the request header cannot be fulfilled."
|
|
191
|
-
},
|
|
192
|
-
[417 /* EXPECTATION_FAILED */]: {
|
|
193
|
-
type: "expectation_failed",
|
|
194
|
-
title: "Expectation Failed",
|
|
195
|
-
code: 417,
|
|
196
|
-
details: "The server cannot meet the requirements of the Expect request-header field."
|
|
197
|
-
},
|
|
198
|
-
[418 /* IM_A_TEAPOT */]: {
|
|
199
|
-
type: "im_a_teapot",
|
|
200
|
-
title: "I'm a Teapot",
|
|
201
|
-
code: 418,
|
|
202
|
-
details: "The server refuses to brew coffee because it is, permanently, a teapot."
|
|
203
|
-
},
|
|
204
|
-
[421 /* MISDIRECTED_REQUEST */]: {
|
|
205
|
-
type: "misdirected_request",
|
|
206
|
-
title: "Misdirected Request",
|
|
207
|
-
code: 421,
|
|
208
|
-
details: "The request was directed at a server that is not able to produce a response."
|
|
209
|
-
},
|
|
210
|
-
[422 /* UNPROCESSABLE_ENTITY */]: {
|
|
211
|
-
type: "unprocessable_entity",
|
|
212
|
-
title: "Unprocessable Entity",
|
|
213
|
-
code: 422,
|
|
214
|
-
details: "The request was well-formed but was unable to be followed due to semantic errors."
|
|
215
|
-
},
|
|
216
|
-
[423 /* LOCKED */]: {
|
|
217
|
-
type: "locked",
|
|
218
|
-
title: "Locked",
|
|
219
|
-
code: 423,
|
|
220
|
-
details: "The resource that is being accessed is locked."
|
|
221
|
-
},
|
|
222
|
-
[424 /* FAILED_DEPENDENCY */]: {
|
|
223
|
-
type: "failed_dependency",
|
|
224
|
-
title: "Failed Dependency",
|
|
225
|
-
code: 424,
|
|
226
|
-
details: "The request failed because it depended on another request that failed."
|
|
227
|
-
},
|
|
228
|
-
[425 /* TOO_EARLY */]: {
|
|
229
|
-
type: "too_early",
|
|
230
|
-
title: "Too Early",
|
|
231
|
-
code: 425,
|
|
232
|
-
details: "The server is unwilling to risk processing a request that might be replayed."
|
|
233
|
-
},
|
|
234
|
-
[426 /* UPGRADE_REQUIRED */]: {
|
|
235
|
-
type: "upgrade_required",
|
|
236
|
-
title: "Upgrade Required",
|
|
237
|
-
code: 426,
|
|
238
|
-
details: "The client should switch to a different protocol."
|
|
239
|
-
},
|
|
240
|
-
[428 /* PRECONDITION_REQUIRED */]: {
|
|
241
|
-
type: "precondition_required",
|
|
242
|
-
title: "Precondition Required",
|
|
243
|
-
code: 428,
|
|
244
|
-
details: "The origin server requires the request to be conditional."
|
|
245
|
-
},
|
|
246
|
-
[429 /* TOO_MANY_REQUESTS */]: {
|
|
247
|
-
type: "too_many_requests",
|
|
248
|
-
title: "Too Many Requests",
|
|
249
|
-
code: 429,
|
|
250
|
-
details: "The user has sent too many requests in a given amount of time.",
|
|
251
|
-
retryAfter: 60
|
|
252
|
-
},
|
|
253
|
-
[431 /* REQUEST_HEADER_FIELDS_TOO_LARGE */]: {
|
|
254
|
-
type: "request_header_fields_too_large",
|
|
255
|
-
title: "Request Header Fields Too Large",
|
|
256
|
-
code: 431,
|
|
257
|
-
details: "The server is unwilling to process the request because its header fields are too large."
|
|
258
|
-
},
|
|
259
|
-
[451 /* UNAVAILABLE_FOR_LEGAL_REASONS */]: {
|
|
260
|
-
type: "unavailable_for_legal_reasons",
|
|
261
|
-
title: "Unavailable For Legal Reasons",
|
|
262
|
-
code: 451,
|
|
263
|
-
details: "The resource is unavailable due to legal demands."
|
|
264
|
-
},
|
|
265
|
-
// ========================================================================
|
|
266
|
-
// 5xx Server Errors
|
|
267
|
-
// ========================================================================
|
|
268
|
-
[500 /* INTERNAL_SERVER_ERROR */]: {
|
|
269
|
-
type: "internal_server_error",
|
|
270
|
-
title: "Internal Server Error",
|
|
271
|
-
code: 500,
|
|
272
|
-
details: "An unexpected error occurred on the server."
|
|
273
|
-
},
|
|
274
|
-
[501 /* NOT_IMPLEMENTED */]: {
|
|
275
|
-
type: "not_implemented",
|
|
276
|
-
title: "Not Implemented",
|
|
277
|
-
code: 501,
|
|
278
|
-
details: "The server does not support the functionality required to fulfill the request."
|
|
279
|
-
},
|
|
280
|
-
[502 /* BAD_GATEWAY */]: {
|
|
281
|
-
type: "bad_gateway",
|
|
282
|
-
title: "Bad Gateway",
|
|
283
|
-
code: 502,
|
|
284
|
-
details: "The server received an invalid response from an upstream server."
|
|
285
|
-
},
|
|
286
|
-
[503 /* SERVICE_UNAVAILABLE */]: {
|
|
287
|
-
type: "service_unavailable",
|
|
288
|
-
title: "Service Unavailable",
|
|
289
|
-
code: 503,
|
|
290
|
-
details: "The server is currently unable to handle the request due to temporary overloading or maintenance.",
|
|
291
|
-
retryAfter: 60,
|
|
292
|
-
resolution: "Try again after a short period or contact support."
|
|
293
|
-
},
|
|
294
|
-
[504 /* GATEWAY_TIMEOUT */]: {
|
|
295
|
-
type: "gateway_timeout",
|
|
296
|
-
title: "Gateway Timeout",
|
|
297
|
-
code: 504,
|
|
298
|
-
details: "The server did not receive a timely response from an upstream server."
|
|
299
|
-
},
|
|
300
|
-
[505 /* HTTP_VERSION_NOT_SUPPORTED */]: {
|
|
301
|
-
type: "http_version_not_supported",
|
|
302
|
-
title: "HTTP Version Not Supported",
|
|
303
|
-
code: 505,
|
|
304
|
-
details: "The server does not support the HTTP protocol version used in the request."
|
|
305
|
-
},
|
|
306
|
-
[506 /* VARIANT_ALSO_NEGOTIATES */]: {
|
|
307
|
-
type: "variant_also_negotiates",
|
|
308
|
-
title: "Variant Also Negotiates",
|
|
309
|
-
code: 506,
|
|
310
|
-
details: "The server has an internal configuration error during content negotiation."
|
|
311
|
-
},
|
|
312
|
-
[507 /* INSUFFICIENT_STORAGE */]: {
|
|
313
|
-
type: "insufficient_storage",
|
|
314
|
-
title: "Insufficient Storage",
|
|
315
|
-
code: 507,
|
|
316
|
-
details: "The server is unable to store the representation needed to complete the request."
|
|
317
|
-
},
|
|
318
|
-
[508 /* LOOP_DETECTED */]: {
|
|
319
|
-
type: "loop_detected",
|
|
320
|
-
title: "Loop Detected",
|
|
321
|
-
code: 508,
|
|
322
|
-
details: "The server detected an infinite loop while processing the request."
|
|
323
|
-
},
|
|
324
|
-
[509 /* BANDWIDTH_LIMIT_EXCEEDED */]: {
|
|
325
|
-
type: "bandwidth_limit_exceeded",
|
|
326
|
-
title: "Bandwidth Limit Exceeded",
|
|
327
|
-
code: 509,
|
|
328
|
-
details: "The server has exceeded the bandwidth limit."
|
|
329
|
-
},
|
|
330
|
-
[510 /* NOT_EXTENDED */]: {
|
|
331
|
-
type: "not_extended",
|
|
332
|
-
title: "Not Extended",
|
|
333
|
-
code: 510,
|
|
334
|
-
details: "Further extensions to the request are required for the server to fulfill it."
|
|
335
|
-
},
|
|
336
|
-
[511 /* NETWORK_AUTHENTICATION_REQUIRED */]: {
|
|
337
|
-
type: "network_authentication_required",
|
|
338
|
-
title: "Network Authentication Required",
|
|
339
|
-
code: 511,
|
|
340
|
-
details: "The client needs to authenticate to gain network access."
|
|
341
|
-
}
|
|
342
|
-
};
|
|
343
|
-
function getErrorDefinition(code) {
|
|
344
|
-
return HttpErrorDefinitions[code] || HttpErrorDefinitions[500];
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/constants/success-definitions.ts
|
|
348
|
-
var HttpSuccessDefinitions = {
|
|
349
|
-
[200 /* OK */]: {
|
|
350
|
-
code: 200,
|
|
351
|
-
description: "The request has succeeded."
|
|
352
|
-
},
|
|
353
|
-
[201 /* CREATED */]: {
|
|
354
|
-
code: 201,
|
|
355
|
-
description: "The request has been fulfilled and resulted in a new resource being created."
|
|
356
|
-
},
|
|
357
|
-
[202 /* ACCEPTED */]: {
|
|
358
|
-
code: 202,
|
|
359
|
-
description: "The request has been accepted for processing, but the processing has not been completed."
|
|
360
|
-
},
|
|
361
|
-
[203 /* NON_AUTHORITATIVE_INFORMATION */]: {
|
|
362
|
-
code: 203,
|
|
363
|
-
description: "The returned meta-information is from a local or third-party copy."
|
|
364
|
-
},
|
|
365
|
-
[204 /* NO_CONTENT */]: {
|
|
366
|
-
code: 204,
|
|
367
|
-
description: "The server successfully processed the request and is not returning any content."
|
|
368
|
-
},
|
|
369
|
-
[205 /* RESET_CONTENT */]: {
|
|
370
|
-
code: 205,
|
|
371
|
-
description: "The server successfully processed the request and requires the requester to reset the document view."
|
|
372
|
-
},
|
|
373
|
-
[206 /* PARTIAL_CONTENT */]: {
|
|
374
|
-
code: 206,
|
|
375
|
-
description: "The server is delivering only part of the resource due to a range header sent by the client."
|
|
376
|
-
},
|
|
377
|
-
[207 /* MULTI_STATUS */]: {
|
|
378
|
-
code: 207,
|
|
379
|
-
description: "The message body contains multiple status codes for multiple independent operations."
|
|
380
|
-
},
|
|
381
|
-
[208 /* ALREADY_REPORTED */]: {
|
|
382
|
-
code: 208,
|
|
383
|
-
description: "The members of a DAV binding have already been enumerated in a preceding part of the response."
|
|
384
|
-
},
|
|
385
|
-
[226 /* IM_USED */]: {
|
|
386
|
-
code: 226,
|
|
387
|
-
description: "The server has fulfilled a GET request and the response is a representation of the result of one or more instance-manipulations."
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
var HttpRedirectDefinitions = {
|
|
391
|
-
[300 /* MULTIPLE_CHOICES */]: {
|
|
392
|
-
code: 300,
|
|
393
|
-
description: "The request has more than one possible response."
|
|
394
|
-
},
|
|
395
|
-
[301 /* MOVED_PERMANENTLY */]: {
|
|
396
|
-
code: 301,
|
|
397
|
-
description: "The URL of the requested resource has been changed permanently."
|
|
398
|
-
},
|
|
399
|
-
[302 /* FOUND */]: {
|
|
400
|
-
code: 302,
|
|
401
|
-
description: "The URI of the requested resource has been changed temporarily."
|
|
402
|
-
},
|
|
403
|
-
[303 /* SEE_OTHER */]: {
|
|
404
|
-
code: 303,
|
|
405
|
-
description: "The response can be found under another URI using the GET method."
|
|
406
|
-
},
|
|
407
|
-
[304 /* NOT_MODIFIED */]: {
|
|
408
|
-
code: 304,
|
|
409
|
-
description: "The resource has not been modified since the version specified by the request headers."
|
|
410
|
-
},
|
|
411
|
-
[305 /* USE_PROXY */]: {
|
|
412
|
-
code: 305,
|
|
413
|
-
description: "The requested resource must be accessed through the proxy."
|
|
414
|
-
},
|
|
415
|
-
[307 /* TEMPORARY_REDIRECT */]: {
|
|
416
|
-
code: 307,
|
|
417
|
-
description: "The request should be repeated with another URI but future requests should use the original URI."
|
|
418
|
-
},
|
|
419
|
-
[308 /* PERMANENT_REDIRECT */]: {
|
|
420
|
-
code: 308,
|
|
421
|
-
description: "The request and all future requests should be repeated using another URI."
|
|
422
|
-
}
|
|
423
|
-
};
|
|
424
|
-
var HttpInfoDefinitions = {
|
|
425
|
-
[100 /* CONTINUE */]: {
|
|
426
|
-
code: 100,
|
|
427
|
-
description: "The initial part of a request has been received and has not yet been rejected by the server."
|
|
428
|
-
},
|
|
429
|
-
[101 /* SWITCHING_PROTOCOLS */]: {
|
|
430
|
-
code: 101,
|
|
431
|
-
description: "The server is switching protocols as requested by the client."
|
|
432
|
-
},
|
|
433
|
-
[102 /* PROCESSING */]: {
|
|
434
|
-
code: 102,
|
|
435
|
-
description: "The server has received and is processing the request, but no response is available yet."
|
|
436
|
-
},
|
|
437
|
-
[103 /* EARLY_HINTS */]: {
|
|
438
|
-
code: 103,
|
|
439
|
-
description: "The server is sending some response headers before the final response."
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
function getSuccessDefinition(code) {
|
|
443
|
-
return HttpSuccessDefinitions[code] || HttpRedirectDefinitions[code] || HttpInfoDefinitions[code] || HttpSuccessDefinitions[200];
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
// src/config/index.ts
|
|
447
|
-
var defaultConfig = {
|
|
448
|
-
isDevelopment: process.env.NODE_ENV === "development",
|
|
449
|
-
includeTimestamp: true,
|
|
450
|
-
customMessages: {},
|
|
451
|
-
responseTransformer: void 0
|
|
452
|
-
};
|
|
453
|
-
var currentConfig = { ...defaultConfig };
|
|
454
|
-
function configure(config) {
|
|
455
|
-
currentConfig = { ...currentConfig, ...config };
|
|
456
|
-
}
|
|
457
|
-
function getConfig() {
|
|
458
|
-
return { ...currentConfig };
|
|
459
|
-
}
|
|
460
|
-
function resetConfig() {
|
|
461
|
-
currentConfig = { ...defaultConfig };
|
|
462
|
-
}
|
|
463
|
-
function isDevelopment() {
|
|
464
|
-
return currentConfig.isDevelopment ?? false;
|
|
465
|
-
}
|
|
466
|
-
function shouldIncludeTimestamp() {
|
|
467
|
-
return currentConfig.includeTimestamp ?? true;
|
|
468
|
-
}
|
|
469
|
-
function getCustomMessage(code) {
|
|
470
|
-
return currentConfig.customMessages?.[code];
|
|
471
|
-
}
|
|
472
|
-
function getResponseTransformer() {
|
|
473
|
-
return currentConfig.responseTransformer;
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
// src/errors/HttpError.ts
|
|
477
|
-
var HttpError = class _HttpError extends Error {
|
|
478
|
-
/**
|
|
479
|
-
* Creates a new HttpError instance
|
|
480
|
-
*
|
|
481
|
-
* @param code - HTTP status code (e.g., 404, 500)
|
|
482
|
-
* @param options - Optional configuration
|
|
483
|
-
*/
|
|
484
|
-
constructor(code, options = {}) {
|
|
485
|
-
const errorInfo = getErrorDefinition(code);
|
|
486
|
-
const customMessage = getCustomMessage(code);
|
|
487
|
-
const finalMessage = options.message ?? customMessage ?? errorInfo.details;
|
|
488
|
-
super(finalMessage);
|
|
489
|
-
this.name = "HttpError";
|
|
490
|
-
this.code = errorInfo.code;
|
|
491
|
-
this.type = errorInfo.type;
|
|
492
|
-
this.title = errorInfo.title;
|
|
493
|
-
this.metadata = options.metadata;
|
|
494
|
-
this.cause = options.cause;
|
|
495
|
-
this.retryAfter = options.retryAfter ?? errorInfo.retryAfter;
|
|
496
|
-
if (typeof Error.captureStackTrace === "function") {
|
|
497
|
-
Error.captureStackTrace(this, _HttpError);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
/**
|
|
501
|
-
* Convert error to plain object for JSON serialization
|
|
502
|
-
*/
|
|
503
|
-
toJSON() {
|
|
504
|
-
return {
|
|
505
|
-
name: this.name,
|
|
506
|
-
code: this.code,
|
|
507
|
-
type: this.type,
|
|
508
|
-
title: this.title,
|
|
509
|
-
message: this.message,
|
|
510
|
-
metadata: this.metadata,
|
|
511
|
-
retryAfter: this.retryAfter
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
// ========================================================================
|
|
515
|
-
// Factory Methods - 4xx Client Errors
|
|
516
|
-
// ========================================================================
|
|
517
|
-
/** 400 Bad Request */
|
|
518
|
-
static badRequest(message, metadata) {
|
|
519
|
-
return new _HttpError(400, { message, metadata });
|
|
520
|
-
}
|
|
521
|
-
/** 401 Unauthorized */
|
|
522
|
-
static unauthorized(message, metadata) {
|
|
523
|
-
return new _HttpError(401, { message, metadata });
|
|
524
|
-
}
|
|
525
|
-
/** 402 Payment Required */
|
|
526
|
-
static paymentRequired(message, metadata) {
|
|
527
|
-
return new _HttpError(402, { message, metadata });
|
|
528
|
-
}
|
|
529
|
-
/** 403 Forbidden */
|
|
530
|
-
static forbidden(message, metadata) {
|
|
531
|
-
return new _HttpError(403, { message, metadata });
|
|
532
|
-
}
|
|
533
|
-
/** 404 Not Found */
|
|
534
|
-
static notFound(message, metadata) {
|
|
535
|
-
return new _HttpError(404, { message, metadata });
|
|
536
|
-
}
|
|
537
|
-
/** 405 Method Not Allowed */
|
|
538
|
-
static methodNotAllowed(message, metadata) {
|
|
539
|
-
return new _HttpError(405, { message, metadata });
|
|
540
|
-
}
|
|
541
|
-
/** 406 Not Acceptable */
|
|
542
|
-
static notAcceptable(message, metadata) {
|
|
543
|
-
return new _HttpError(406, { message, metadata });
|
|
544
|
-
}
|
|
545
|
-
/** 407 Proxy Authentication Required */
|
|
546
|
-
static proxyAuthenticationRequired(message, metadata) {
|
|
547
|
-
return new _HttpError(407, { message, metadata });
|
|
548
|
-
}
|
|
549
|
-
/** 408 Request Timeout */
|
|
550
|
-
static requestTimeout(message, metadata) {
|
|
551
|
-
return new _HttpError(408, { message, metadata });
|
|
552
|
-
}
|
|
553
|
-
/** 409 Conflict */
|
|
554
|
-
static conflict(message, metadata) {
|
|
555
|
-
return new _HttpError(409, { message, metadata });
|
|
556
|
-
}
|
|
557
|
-
/** 410 Gone */
|
|
558
|
-
static gone(message, metadata) {
|
|
559
|
-
return new _HttpError(410, { message, metadata });
|
|
560
|
-
}
|
|
561
|
-
/** 411 Length Required */
|
|
562
|
-
static lengthRequired(message, metadata) {
|
|
563
|
-
return new _HttpError(411, { message, metadata });
|
|
564
|
-
}
|
|
565
|
-
/** 412 Precondition Failed */
|
|
566
|
-
static preconditionFailed(message, metadata) {
|
|
567
|
-
return new _HttpError(412, { message, metadata });
|
|
568
|
-
}
|
|
569
|
-
/** 413 Payload Too Large */
|
|
570
|
-
static payloadTooLarge(message, metadata) {
|
|
571
|
-
return new _HttpError(413, { message, metadata });
|
|
572
|
-
}
|
|
573
|
-
/** 414 URI Too Long */
|
|
574
|
-
static uriTooLong(message, metadata) {
|
|
575
|
-
return new _HttpError(414, { message, metadata });
|
|
576
|
-
}
|
|
577
|
-
/** 415 Unsupported Media Type */
|
|
578
|
-
static unsupportedMediaType(message, metadata) {
|
|
579
|
-
return new _HttpError(415, { message, metadata });
|
|
580
|
-
}
|
|
581
|
-
/** 416 Range Not Satisfiable */
|
|
582
|
-
static rangeNotSatisfiable(message, metadata) {
|
|
583
|
-
return new _HttpError(416, { message, metadata });
|
|
584
|
-
}
|
|
585
|
-
/** 417 Expectation Failed */
|
|
586
|
-
static expectationFailed(message, metadata) {
|
|
587
|
-
return new _HttpError(417, { message, metadata });
|
|
588
|
-
}
|
|
589
|
-
/** 418 I'm a Teapot */
|
|
590
|
-
static imATeapot(message, metadata) {
|
|
591
|
-
return new _HttpError(418, { message, metadata });
|
|
592
|
-
}
|
|
593
|
-
/** 421 Misdirected Request */
|
|
594
|
-
static misdirectedRequest(message, metadata) {
|
|
595
|
-
return new _HttpError(421, { message, metadata });
|
|
596
|
-
}
|
|
597
|
-
/** 422 Unprocessable Entity */
|
|
598
|
-
static unprocessableEntity(message, metadata) {
|
|
599
|
-
return new _HttpError(422, { message, metadata });
|
|
600
|
-
}
|
|
601
|
-
/** 423 Locked */
|
|
602
|
-
static locked(message, metadata) {
|
|
603
|
-
return new _HttpError(423, { message, metadata });
|
|
604
|
-
}
|
|
605
|
-
/** 424 Failed Dependency */
|
|
606
|
-
static failedDependency(message, metadata) {
|
|
607
|
-
return new _HttpError(424, { message, metadata });
|
|
608
|
-
}
|
|
609
|
-
/** 425 Too Early */
|
|
610
|
-
static tooEarly(message, metadata) {
|
|
611
|
-
return new _HttpError(425, { message, metadata });
|
|
612
|
-
}
|
|
613
|
-
/** 426 Upgrade Required */
|
|
614
|
-
static upgradeRequired(message, metadata) {
|
|
615
|
-
return new _HttpError(426, { message, metadata });
|
|
616
|
-
}
|
|
617
|
-
/** 428 Precondition Required */
|
|
618
|
-
static preconditionRequired(message, metadata) {
|
|
619
|
-
return new _HttpError(428, { message, metadata });
|
|
620
|
-
}
|
|
621
|
-
/** 429 Too Many Requests */
|
|
622
|
-
static tooManyRequests(message, retryAfter, metadata) {
|
|
623
|
-
return new _HttpError(429, { message, metadata, retryAfter });
|
|
624
|
-
}
|
|
625
|
-
/** 431 Request Header Fields Too Large */
|
|
626
|
-
static requestHeaderFieldsTooLarge(message, metadata) {
|
|
627
|
-
return new _HttpError(431, { message, metadata });
|
|
628
|
-
}
|
|
629
|
-
/** 451 Unavailable For Legal Reasons */
|
|
630
|
-
static unavailableForLegalReasons(message, metadata) {
|
|
631
|
-
return new _HttpError(451, { message, metadata });
|
|
632
|
-
}
|
|
633
|
-
// ========================================================================
|
|
634
|
-
// Factory Methods - 5xx Server Errors
|
|
635
|
-
// ========================================================================
|
|
636
|
-
/** 500 Internal Server Error */
|
|
637
|
-
static internalServerError(message, metadata) {
|
|
638
|
-
return new _HttpError(500, { message, metadata });
|
|
639
|
-
}
|
|
640
|
-
/** 501 Not Implemented */
|
|
641
|
-
static notImplemented(message, metadata) {
|
|
642
|
-
return new _HttpError(501, { message, metadata });
|
|
643
|
-
}
|
|
644
|
-
/** 502 Bad Gateway */
|
|
645
|
-
static badGateway(message, metadata) {
|
|
646
|
-
return new _HttpError(502, { message, metadata });
|
|
647
|
-
}
|
|
648
|
-
/** 503 Service Unavailable */
|
|
649
|
-
static serviceUnavailable(message, retryAfter, metadata) {
|
|
650
|
-
return new _HttpError(503, { message, metadata, retryAfter });
|
|
651
|
-
}
|
|
652
|
-
/** 504 Gateway Timeout */
|
|
653
|
-
static gatewayTimeout(message, metadata) {
|
|
654
|
-
return new _HttpError(504, { message, metadata });
|
|
655
|
-
}
|
|
656
|
-
/** 505 HTTP Version Not Supported */
|
|
657
|
-
static httpVersionNotSupported(message, metadata) {
|
|
658
|
-
return new _HttpError(505, { message, metadata });
|
|
659
|
-
}
|
|
660
|
-
/** 506 Variant Also Negotiates */
|
|
661
|
-
static variantAlsoNegotiates(message, metadata) {
|
|
662
|
-
return new _HttpError(506, { message, metadata });
|
|
663
|
-
}
|
|
664
|
-
/** 507 Insufficient Storage */
|
|
665
|
-
static insufficientStorage(message, metadata) {
|
|
666
|
-
return new _HttpError(507, { message, metadata });
|
|
667
|
-
}
|
|
668
|
-
/** 508 Loop Detected */
|
|
669
|
-
static loopDetected(message, metadata) {
|
|
670
|
-
return new _HttpError(508, { message, metadata });
|
|
671
|
-
}
|
|
672
|
-
/** 509 Bandwidth Limit Exceeded */
|
|
673
|
-
static bandwidthLimitExceeded(message, metadata) {
|
|
674
|
-
return new _HttpError(509, { message, metadata });
|
|
675
|
-
}
|
|
676
|
-
/** 510 Not Extended */
|
|
677
|
-
static notExtended(message, metadata) {
|
|
678
|
-
return new _HttpError(510, { message, metadata });
|
|
679
|
-
}
|
|
680
|
-
/** 511 Network Authentication Required */
|
|
681
|
-
static networkAuthenticationRequired(message, metadata) {
|
|
682
|
-
return new _HttpError(511, { message, metadata });
|
|
683
|
-
}
|
|
684
|
-
// ========================================================================
|
|
685
|
-
// Utility Methods
|
|
686
|
-
// ========================================================================
|
|
687
|
-
/**
|
|
688
|
-
* Create an HttpError from an unknown error
|
|
689
|
-
*/
|
|
690
|
-
static fromError(error, fallbackCode = 500) {
|
|
691
|
-
if (error instanceof _HttpError) {
|
|
692
|
-
return error;
|
|
693
|
-
}
|
|
694
|
-
if (error instanceof Error) {
|
|
695
|
-
return new _HttpError(fallbackCode, {
|
|
696
|
-
message: error.message,
|
|
697
|
-
cause: error
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
return new _HttpError(fallbackCode, {
|
|
701
|
-
message: String(error)
|
|
4
|
+
// src/errors/catalog.ts
|
|
5
|
+
function createErrorCatalog(catalog) {
|
|
6
|
+
const factories = {};
|
|
7
|
+
for (const key of Object.keys(catalog)) {
|
|
8
|
+
const entry = catalog[key];
|
|
9
|
+
factories[key] = (message, options = {}) => new HttpError(entry.status, {
|
|
10
|
+
...options,
|
|
11
|
+
message: message ?? entry.message ?? options.message,
|
|
12
|
+
errorCode: String(key),
|
|
13
|
+
expose: options.expose ?? entry.expose,
|
|
14
|
+
metadata: options.metadata ?? entry.metadata
|
|
702
15
|
});
|
|
703
16
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
*/
|
|
707
|
-
static isHttpError(error) {
|
|
708
|
-
return error instanceof _HttpError;
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Check if error is a client error (4xx)
|
|
712
|
-
*/
|
|
713
|
-
isClientError() {
|
|
714
|
-
return this.code >= 400 && this.code < 500;
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Check if error is a server error (5xx)
|
|
718
|
-
*/
|
|
719
|
-
isServerError() {
|
|
720
|
-
return this.code >= 500 && this.code < 600;
|
|
721
|
-
}
|
|
722
|
-
};
|
|
17
|
+
return factories;
|
|
18
|
+
}
|
|
723
19
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
* Format a success response
|
|
728
|
-
*
|
|
729
|
-
* @param config - Success response configuration
|
|
730
|
-
* @returns Formatted success response object
|
|
731
|
-
*/
|
|
732
|
-
static success(config = {}) {
|
|
733
|
-
const {
|
|
734
|
-
data = null,
|
|
735
|
-
message,
|
|
736
|
-
statusCode = 200 /* OK */,
|
|
737
|
-
metadata = {}
|
|
738
|
-
} = config;
|
|
739
|
-
const successInfo = getSuccessDefinition(statusCode);
|
|
740
|
-
const response = {
|
|
741
|
-
success: true,
|
|
742
|
-
status_code: successInfo.code
|
|
743
|
-
};
|
|
744
|
-
if (shouldIncludeTimestamp()) {
|
|
745
|
-
response.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
746
|
-
}
|
|
747
|
-
if (statusCode !== 204 /* NO_CONTENT */ && statusCode !== 205 /* RESET_CONTENT */) {
|
|
748
|
-
if (data !== null && data !== void 0) {
|
|
749
|
-
response.data = data;
|
|
750
|
-
}
|
|
751
|
-
}
|
|
752
|
-
if (message) {
|
|
753
|
-
response.message = message;
|
|
754
|
-
}
|
|
755
|
-
if (Object.keys(metadata).length > 0) {
|
|
756
|
-
response.metadata = metadata;
|
|
757
|
-
}
|
|
758
|
-
const transformer = getResponseTransformer();
|
|
759
|
-
if (transformer) {
|
|
760
|
-
return transformer(response);
|
|
761
|
-
}
|
|
762
|
-
return response;
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* Format an error response
|
|
766
|
-
*
|
|
767
|
-
* @param error - HttpError instance
|
|
768
|
-
* @param config - Optional error response configuration
|
|
769
|
-
* @returns Formatted error response object
|
|
770
|
-
*/
|
|
771
|
-
static error(error, config = {}) {
|
|
772
|
-
const { includeStack, additionalFields } = config;
|
|
773
|
-
const response = {
|
|
774
|
-
success: false,
|
|
775
|
-
status_code: error.code,
|
|
776
|
-
error: {
|
|
777
|
-
type: error.type,
|
|
778
|
-
title: error.title,
|
|
779
|
-
message: error.message
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
if (shouldIncludeTimestamp()) {
|
|
783
|
-
response.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
784
|
-
}
|
|
785
|
-
if (includeStack ?? isDevelopment()) {
|
|
786
|
-
response.error.details = error.stack;
|
|
787
|
-
}
|
|
788
|
-
if (error.retryAfter) {
|
|
789
|
-
response.retry_after = error.retryAfter;
|
|
790
|
-
}
|
|
791
|
-
if (error.metadata) {
|
|
792
|
-
response.metadata = error.metadata;
|
|
793
|
-
}
|
|
794
|
-
if (additionalFields) {
|
|
795
|
-
Object.assign(response, additionalFields);
|
|
796
|
-
}
|
|
797
|
-
const transformer = getResponseTransformer();
|
|
798
|
-
if (transformer) {
|
|
799
|
-
return transformer(response);
|
|
800
|
-
}
|
|
801
|
-
return response;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
* Format a response from any error (converts to HttpError first)
|
|
805
|
-
*
|
|
806
|
-
* @param error - Any error type
|
|
807
|
-
* @param config - Optional error response configuration
|
|
808
|
-
* @returns Formatted error response object
|
|
809
|
-
*/
|
|
810
|
-
static fromError(error, config = {}) {
|
|
811
|
-
const httpError = HttpError.fromError(error);
|
|
812
|
-
return _HttpResponse.error(httpError, config);
|
|
813
|
-
}
|
|
814
|
-
// ========================================================================
|
|
815
|
-
// Convenience Methods
|
|
816
|
-
// ========================================================================
|
|
817
|
-
/** 200 OK */
|
|
818
|
-
static ok(data, message) {
|
|
819
|
-
return _HttpResponse.success({ data, message, statusCode: 200 /* OK */ });
|
|
820
|
-
}
|
|
821
|
-
/** 201 Created */
|
|
822
|
-
static created(data, message) {
|
|
823
|
-
return _HttpResponse.success({ data, message, statusCode: 201 /* CREATED */ });
|
|
824
|
-
}
|
|
825
|
-
/** 202 Accepted */
|
|
826
|
-
static accepted(data, message) {
|
|
827
|
-
return _HttpResponse.success({ data, message, statusCode: 202 /* ACCEPTED */ });
|
|
828
|
-
}
|
|
829
|
-
/** 204 No Content */
|
|
830
|
-
static noContent() {
|
|
831
|
-
return _HttpResponse.success({ statusCode: 204 /* NO_CONTENT */ });
|
|
832
|
-
}
|
|
833
|
-
/** 206 Partial Content */
|
|
834
|
-
static partialContent(data, message) {
|
|
835
|
-
return _HttpResponse.success({ data, message, statusCode: 206 /* PARTIAL_CONTENT */ });
|
|
836
|
-
}
|
|
837
|
-
/** 304 Not Modified */
|
|
838
|
-
static notModified() {
|
|
839
|
-
return _HttpResponse.success({ statusCode: 304 /* NOT_MODIFIED */ });
|
|
840
|
-
}
|
|
841
|
-
// ========================================================================
|
|
842
|
-
// Utility Methods
|
|
843
|
-
// ========================================================================
|
|
844
|
-
/**
|
|
845
|
-
* Check if a response is a success response
|
|
846
|
-
*/
|
|
847
|
-
static isSuccess(response) {
|
|
848
|
-
return response.success === true;
|
|
849
|
-
}
|
|
850
|
-
/**
|
|
851
|
-
* Check if a response is an error response
|
|
852
|
-
*/
|
|
853
|
-
static isError(response) {
|
|
854
|
-
return response.success === false;
|
|
855
|
-
}
|
|
856
|
-
/**
|
|
857
|
-
* Create a paginated success response
|
|
858
|
-
*/
|
|
859
|
-
static paginated(data, pagination, message) {
|
|
860
|
-
return _HttpResponse.success({
|
|
861
|
-
data,
|
|
862
|
-
message,
|
|
863
|
-
metadata: {
|
|
864
|
-
pagination: {
|
|
865
|
-
page: pagination.page,
|
|
866
|
-
limit: pagination.limit,
|
|
867
|
-
total: pagination.total,
|
|
868
|
-
total_pages: pagination.totalPages ?? Math.ceil(pagination.total / pagination.limit),
|
|
869
|
-
has_next: pagination.page < (pagination.totalPages ?? Math.ceil(pagination.total / pagination.limit)),
|
|
870
|
-
has_prev: pagination.page > 1
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
});
|
|
874
|
-
}
|
|
875
|
-
};
|
|
876
|
-
export {
|
|
877
|
-
HttpClientErrorCode,
|
|
878
|
-
HttpError,
|
|
879
|
-
HttpErrorCode,
|
|
880
|
-
HttpErrorDefinitions,
|
|
881
|
-
HttpInfoCode,
|
|
882
|
-
HttpInfoDefinitions,
|
|
883
|
-
HttpRedirectCode,
|
|
884
|
-
HttpRedirectDefinitions,
|
|
885
|
-
HttpResponse,
|
|
886
|
-
HttpServerErrorCode,
|
|
887
|
-
HttpSuccessCode,
|
|
888
|
-
HttpSuccessDefinitions,
|
|
889
|
-
configure,
|
|
890
|
-
getConfig,
|
|
891
|
-
getErrorDefinition,
|
|
892
|
-
getSuccessDefinition,
|
|
893
|
-
isDevelopment,
|
|
894
|
-
resetConfig
|
|
895
|
-
};
|
|
20
|
+
export { createErrorCatalog };
|
|
21
|
+
//# sourceMappingURL=index.mjs.map
|
|
22
|
+
//# sourceMappingURL=index.mjs.map
|