@adonisjs/http-server 8.0.0-next.12 → 8.0.0-next.14
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/build/define_config-Dh5SpqNg.js +2446 -0
- package/build/factories/http_context.d.ts +4 -4
- package/build/factories/main.d.ts +2 -2
- package/build/factories/main.js +163 -347
- package/build/factories/request.d.ts +4 -4
- package/build/factories/response.d.ts +4 -4
- package/build/factories/router.d.ts +1 -1
- package/build/factories/server_factory.d.ts +1 -1
- package/build/factories/url_builder_factory.d.ts +1 -1
- package/build/helpers-C_2HouOe.js +52 -0
- package/build/helpers-oKG4uNSM.js +686 -0
- package/build/index.d.ts +2 -2
- package/build/index.js +157 -375
- package/build/src/client/url_builder.js +3 -12
- package/build/src/cookies/client.d.ts +1 -1
- package/build/src/cookies/drivers/encrypted.d.ts +1 -1
- package/build/src/cookies/drivers/signed.d.ts +1 -1
- package/build/src/cookies/parser.d.ts +1 -1
- package/build/src/cookies/serializer.d.ts +1 -1
- package/build/src/debug.d.ts +1 -1
- package/build/src/exception_handler.d.ts +7 -0
- package/build/src/helpers.d.ts +1 -1
- package/build/src/helpers.js +3 -26
- package/build/src/http_context/main.d.ts +7 -7
- package/build/src/qs.d.ts +1 -1
- package/build/src/redirect.d.ts +2 -2
- package/build/src/request.d.ts +2 -2
- package/build/src/response.d.ts +5 -5
- package/build/src/router/main.d.ts +1 -1
- package/build/src/router/signed_url_builder.d.ts +1 -1
- package/build/src/server/main.d.ts +6 -6
- package/build/src/types/main.js +1 -0
- package/build/src/types/response.d.ts +6 -1
- package/build/url_builder-piNQy-CF.js +114 -0
- package/package.json +24 -22
- package/build/chunk-2QM3D5BN.js +0 -87
- package/build/chunk-77CSRFCU.js +0 -131
- package/build/chunk-L2UOVWDK.js +0 -4441
- package/build/chunk-QDK57QGB.js +0 -1176
package/build/index.js
CHANGED
|
@@ -1,378 +1,160 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
E_CANNOT_LOOKUP_ROUTE,
|
|
6
|
-
E_HTTP_EXCEPTION,
|
|
7
|
-
E_HTTP_REQUEST_ABORTED,
|
|
8
|
-
E_ROUTE_NOT_FOUND,
|
|
9
|
-
HttpContext,
|
|
10
|
-
Qs,
|
|
11
|
-
Redirect,
|
|
12
|
-
Request,
|
|
13
|
-
Response,
|
|
14
|
-
ResponseStatus,
|
|
15
|
-
Router,
|
|
16
|
-
Server,
|
|
17
|
-
defineConfig,
|
|
18
|
-
errors_exports
|
|
19
|
-
} from "./chunk-L2UOVWDK.js";
|
|
20
|
-
import {
|
|
21
|
-
BriskRoute,
|
|
22
|
-
Route,
|
|
23
|
-
RouteGroup,
|
|
24
|
-
RouteResource,
|
|
25
|
-
canWriteResponseBody,
|
|
26
|
-
parseRange,
|
|
27
|
-
tracing_channels_exports
|
|
28
|
-
} from "./chunk-QDK57QGB.js";
|
|
29
|
-
import "./chunk-77CSRFCU.js";
|
|
30
|
-
import "./chunk-2QM3D5BN.js";
|
|
31
|
-
|
|
32
|
-
// src/exception_handler.ts
|
|
33
|
-
import is from "@sindresorhus/is";
|
|
1
|
+
import { C as canWriteResponseBody, S as tracing_channels_exports, _ as Route, g as BriskRoute, h as RouteResource, m as RouteGroup, u as parseRange } from "./helpers-oKG4uNSM.js";
|
|
2
|
+
import { _ as Qs, a as CookieSerializer, c as HttpRequest, d as Redirect, f as E_CANNOT_LOOKUP_ROUTE, g as errors_exports, h as E_ROUTE_NOT_FOUND, i as HttpResponse, l as CookieParser, m as E_HTTP_REQUEST_ABORTED, n as Server, o as ResponseStatus, p as E_HTTP_EXCEPTION, r as HttpContext, s as Router, t as defineConfig, u as CookieClient } from "./define_config-Dh5SpqNg.js";
|
|
3
|
+
import "./helpers-C_2HouOe.js";
|
|
4
|
+
import "./url_builder-piNQy-CF.js";
|
|
34
5
|
import Macroable from "@poppinss/macroable";
|
|
6
|
+
import is from "@sindresorhus/is";
|
|
35
7
|
var ExceptionHandler = class extends Macroable {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
ctx.response.status(error.status).send({ message: error.message });
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Renders an error as a JSON API compliant response
|
|
191
|
-
* Follows JSON API specification for error objects
|
|
192
|
-
* @param error - HTTP error to render
|
|
193
|
-
* @param ctx - HTTP context for the request
|
|
194
|
-
*/
|
|
195
|
-
async renderErrorAsJSONAPI(error, ctx) {
|
|
196
|
-
if (this.isDebuggingEnabled(ctx)) {
|
|
197
|
-
const { Youch } = await import("youch");
|
|
198
|
-
const json = await new Youch().toJSON(error);
|
|
199
|
-
ctx.response.status(error.status).send(json);
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
ctx.response.status(error.status).send({
|
|
203
|
-
errors: [
|
|
204
|
-
{
|
|
205
|
-
title: error.message,
|
|
206
|
-
code: error.code,
|
|
207
|
-
status: error.status
|
|
208
|
-
}
|
|
209
|
-
]
|
|
210
|
-
});
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Renders an error as an HTML response
|
|
214
|
-
* Uses status pages if configured, otherwise shows debug info or simple message
|
|
215
|
-
* @param error - HTTP error to render
|
|
216
|
-
* @param ctx - HTTP context for the request
|
|
217
|
-
*/
|
|
218
|
-
async renderErrorAsHTML(error, ctx) {
|
|
219
|
-
const statusPages = this.#expandStatusPages();
|
|
220
|
-
if (this.renderStatusPages && statusPages[error.status]) {
|
|
221
|
-
const statusPageResponse = await statusPages[error.status](error, ctx);
|
|
222
|
-
if (canWriteResponseBody(statusPageResponse, ctx)) {
|
|
223
|
-
return ctx.response.safeStatus(error.status).send(statusPageResponse);
|
|
224
|
-
}
|
|
225
|
-
return statusPageResponse;
|
|
226
|
-
}
|
|
227
|
-
if (this.isDebuggingEnabled(ctx)) {
|
|
228
|
-
const { Youch } = await import("youch");
|
|
229
|
-
const html = await new Youch().toHTML(error, {
|
|
230
|
-
request: ctx.request.request,
|
|
231
|
-
cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
|
|
232
|
-
});
|
|
233
|
-
ctx.response.status(error.status).send(html);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Renders validation error messages as a JSON response
|
|
240
|
-
* Returns errors in a simple format with field-specific messages
|
|
241
|
-
* @param error - Validation error containing messages array
|
|
242
|
-
* @param ctx - HTTP context for the request
|
|
243
|
-
*/
|
|
244
|
-
async renderValidationErrorAsJSON(error, ctx) {
|
|
245
|
-
ctx.response.status(error.status).send({
|
|
246
|
-
errors: error.messages
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Renders validation error messages as JSON API compliant response
|
|
251
|
-
* Transforms validation messages to JSON API error object format
|
|
252
|
-
* @param error - Validation error containing messages array
|
|
253
|
-
* @param ctx - HTTP context for the request
|
|
254
|
-
*/
|
|
255
|
-
async renderValidationErrorAsJSONAPI(error, ctx) {
|
|
256
|
-
ctx.response.status(error.status).send({
|
|
257
|
-
errors: error.messages.map((message) => {
|
|
258
|
-
return {
|
|
259
|
-
title: message.message,
|
|
260
|
-
code: message.rule,
|
|
261
|
-
source: {
|
|
262
|
-
pointer: message.field
|
|
263
|
-
},
|
|
264
|
-
meta: message.meta
|
|
265
|
-
};
|
|
266
|
-
})
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Renders validation error messages as an HTML response
|
|
271
|
-
* Creates simple HTML list of field errors separated by line breaks
|
|
272
|
-
* @param error - Validation error containing messages array
|
|
273
|
-
* @param ctx - HTTP context for the request
|
|
274
|
-
*/
|
|
275
|
-
async renderValidationErrorAsHTML(error, ctx) {
|
|
276
|
-
ctx.response.status(error.status).type("html").send(
|
|
277
|
-
error.messages.map((message) => {
|
|
278
|
-
return `${message.field} - ${message.message}`;
|
|
279
|
-
}).join("<br />")
|
|
280
|
-
);
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Renders an error to the appropriate response format based on content negotiation
|
|
284
|
-
* Supports HTML, JSON API, and JSON formats based on Accept headers
|
|
285
|
-
* @param error - HTTP error to render
|
|
286
|
-
* @param ctx - HTTP context for the request
|
|
287
|
-
*/
|
|
288
|
-
renderError(error, ctx) {
|
|
289
|
-
switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
|
|
290
|
-
case "application/vnd.api+json":
|
|
291
|
-
return this.renderErrorAsJSONAPI(error, ctx);
|
|
292
|
-
case "json":
|
|
293
|
-
return this.renderErrorAsJSON(error, ctx);
|
|
294
|
-
case "html":
|
|
295
|
-
default:
|
|
296
|
-
return this.renderErrorAsHTML(error, ctx);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Renders validation errors to the appropriate response format based on content negotiation
|
|
301
|
-
* Supports HTML, JSON API, and JSON formats for validation error messages
|
|
302
|
-
* @param error - Validation error to render
|
|
303
|
-
* @param ctx - HTTP context for the request
|
|
304
|
-
*/
|
|
305
|
-
renderValidationError(error, ctx) {
|
|
306
|
-
switch (ctx.request.accepts(["html", "application/vnd.api+json", "json"])) {
|
|
307
|
-
case "application/vnd.api+json":
|
|
308
|
-
return this.renderValidationErrorAsJSONAPI(error, ctx);
|
|
309
|
-
case "json":
|
|
310
|
-
return this.renderValidationErrorAsJSON(error, ctx);
|
|
311
|
-
case "html":
|
|
312
|
-
default:
|
|
313
|
-
return this.renderValidationErrorAsHTML(error, ctx);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Reports an error to logging systems if reporting is enabled
|
|
318
|
-
* Allows errors to self-report via their own report method if available
|
|
319
|
-
* @param error - Any error object to report
|
|
320
|
-
* @param ctx - HTTP context for additional reporting context
|
|
321
|
-
*/
|
|
322
|
-
async report(error, ctx) {
|
|
323
|
-
const httpError = this.#toHttpError(error);
|
|
324
|
-
if (!this.shouldReport(httpError)) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (typeof httpError.report === "function") {
|
|
328
|
-
httpError.report(httpError, ctx);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
const level = this.getErrorLogLevel(httpError);
|
|
332
|
-
ctx.logger.log(
|
|
333
|
-
level,
|
|
334
|
-
{
|
|
335
|
-
...level === "error" || level === "fatal" ? { err: httpError } : {},
|
|
336
|
-
...this.context(ctx)
|
|
337
|
-
},
|
|
338
|
-
httpError.message
|
|
339
|
-
);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Handles errors during HTTP request processing
|
|
343
|
-
* Delegates to error's own handle method if available, otherwise renders response
|
|
344
|
-
* @param error - Any error object to handle
|
|
345
|
-
* @param ctx - HTTP context for error handling
|
|
346
|
-
*/
|
|
347
|
-
async handle(error, ctx) {
|
|
348
|
-
const httpError = this.#toHttpError(error);
|
|
349
|
-
if (typeof httpError.handle === "function") {
|
|
350
|
-
return httpError.handle(httpError, ctx);
|
|
351
|
-
}
|
|
352
|
-
if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) {
|
|
353
|
-
return this.renderValidationError(httpError, ctx);
|
|
354
|
-
}
|
|
355
|
-
return this.renderError(httpError, ctx);
|
|
356
|
-
}
|
|
357
|
-
};
|
|
358
|
-
export {
|
|
359
|
-
BriskRoute,
|
|
360
|
-
CookieClient,
|
|
361
|
-
CookieParser,
|
|
362
|
-
CookieSerializer,
|
|
363
|
-
ExceptionHandler,
|
|
364
|
-
HttpContext,
|
|
365
|
-
Qs,
|
|
366
|
-
Redirect,
|
|
367
|
-
Request,
|
|
368
|
-
Response,
|
|
369
|
-
ResponseStatus,
|
|
370
|
-
Route,
|
|
371
|
-
RouteGroup,
|
|
372
|
-
RouteResource,
|
|
373
|
-
Router,
|
|
374
|
-
Server,
|
|
375
|
-
defineConfig,
|
|
376
|
-
errors_exports as errors,
|
|
377
|
-
tracing_channels_exports as tracingChannels
|
|
8
|
+
#expandedStatusPages;
|
|
9
|
+
debug = process.env.NODE_ENV !== "production";
|
|
10
|
+
renderStatusPages = process.env.NODE_ENV === "production";
|
|
11
|
+
statusPages = {};
|
|
12
|
+
reportErrors = true;
|
|
13
|
+
ignoreExceptions = [
|
|
14
|
+
E_HTTP_EXCEPTION,
|
|
15
|
+
E_ROUTE_NOT_FOUND,
|
|
16
|
+
E_CANNOT_LOOKUP_ROUTE,
|
|
17
|
+
E_HTTP_REQUEST_ABORTED
|
|
18
|
+
];
|
|
19
|
+
ignoreStatuses = [
|
|
20
|
+
400,
|
|
21
|
+
422,
|
|
22
|
+
401
|
|
23
|
+
];
|
|
24
|
+
ignoreCodes = [];
|
|
25
|
+
#expandStatusPages() {
|
|
26
|
+
if (!this.#expandedStatusPages) this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
|
|
27
|
+
const renderer = this.statusPages[range];
|
|
28
|
+
result = Object.assign(result, parseRange(range, renderer));
|
|
29
|
+
return result;
|
|
30
|
+
}, {});
|
|
31
|
+
return this.#expandedStatusPages;
|
|
32
|
+
}
|
|
33
|
+
toHttpError(error) {
|
|
34
|
+
const httpError = is.object(error) ? error : new Error(String(error));
|
|
35
|
+
if (!httpError.message) httpError.message = "Internal server error";
|
|
36
|
+
if (!httpError.status) httpError.status = 500;
|
|
37
|
+
return httpError;
|
|
38
|
+
}
|
|
39
|
+
context(ctx) {
|
|
40
|
+
const requestId = ctx.request.id();
|
|
41
|
+
return requestId ? { "x-request-id": requestId } : {};
|
|
42
|
+
}
|
|
43
|
+
getErrorLogLevel(error) {
|
|
44
|
+
if (error.status >= 500) return "error";
|
|
45
|
+
if (error.status >= 400) return "warn";
|
|
46
|
+
return "info";
|
|
47
|
+
}
|
|
48
|
+
isDebuggingEnabled(_) {
|
|
49
|
+
return this.debug;
|
|
50
|
+
}
|
|
51
|
+
shouldReport(error) {
|
|
52
|
+
if (this.reportErrors === false) return false;
|
|
53
|
+
if (this.ignoreStatuses.includes(error.status)) return false;
|
|
54
|
+
if (error.code && this.ignoreCodes.includes(error.code)) return false;
|
|
55
|
+
if (this.ignoreExceptions.find((exception) => error instanceof exception)) return false;
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
async renderErrorAsJSON(error, ctx) {
|
|
59
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
60
|
+
const { Youch } = await import("youch");
|
|
61
|
+
const json = await new Youch().toJSON(error);
|
|
62
|
+
ctx.response.status(error.status).send(json);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
ctx.response.status(error.status).send({ message: error.message });
|
|
66
|
+
}
|
|
67
|
+
async renderErrorAsJSONAPI(error, ctx) {
|
|
68
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
69
|
+
const { Youch } = await import("youch");
|
|
70
|
+
const json = await new Youch().toJSON(error);
|
|
71
|
+
ctx.response.status(error.status).send(json);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
ctx.response.status(error.status).send({ errors: [{
|
|
75
|
+
title: error.message,
|
|
76
|
+
code: error.code,
|
|
77
|
+
status: error.status
|
|
78
|
+
}] });
|
|
79
|
+
}
|
|
80
|
+
async renderErrorAsHTML(error, ctx) {
|
|
81
|
+
const statusPages = this.#expandStatusPages();
|
|
82
|
+
if (this.renderStatusPages && statusPages[error.status]) {
|
|
83
|
+
const statusPageResponse = await statusPages[error.status](error, ctx);
|
|
84
|
+
if (canWriteResponseBody(statusPageResponse, ctx)) return ctx.response.safeStatus(error.status).send(statusPageResponse);
|
|
85
|
+
return statusPageResponse;
|
|
86
|
+
}
|
|
87
|
+
if (this.isDebuggingEnabled(ctx)) {
|
|
88
|
+
const { Youch } = await import("youch");
|
|
89
|
+
const html = await new Youch().toHTML(error, {
|
|
90
|
+
request: ctx.request.request,
|
|
91
|
+
cspNonce: "nonce" in ctx.response ? ctx.response.nonce : void 0
|
|
92
|
+
});
|
|
93
|
+
ctx.response.status(error.status).send(html);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
|
|
97
|
+
}
|
|
98
|
+
async renderValidationErrorAsJSON(error, ctx) {
|
|
99
|
+
ctx.response.status(error.status).send({ errors: error.messages });
|
|
100
|
+
}
|
|
101
|
+
async renderValidationErrorAsJSONAPI(error, ctx) {
|
|
102
|
+
ctx.response.status(error.status).send({ errors: error.messages.map((message) => {
|
|
103
|
+
return {
|
|
104
|
+
title: message.message,
|
|
105
|
+
code: message.rule,
|
|
106
|
+
source: { pointer: message.field },
|
|
107
|
+
meta: message.meta
|
|
108
|
+
};
|
|
109
|
+
}) });
|
|
110
|
+
}
|
|
111
|
+
async renderValidationErrorAsHTML(error, ctx) {
|
|
112
|
+
ctx.response.status(error.status).type("html").send(error.messages.map((message) => {
|
|
113
|
+
return `${message.field} - ${message.message}`;
|
|
114
|
+
}).join("<br />"));
|
|
115
|
+
}
|
|
116
|
+
renderError(error, ctx) {
|
|
117
|
+
switch (ctx.request.accepts([
|
|
118
|
+
"html",
|
|
119
|
+
"application/vnd.api+json",
|
|
120
|
+
"json"
|
|
121
|
+
])) {
|
|
122
|
+
case "application/vnd.api+json": return this.renderErrorAsJSONAPI(error, ctx);
|
|
123
|
+
case "json": return this.renderErrorAsJSON(error, ctx);
|
|
124
|
+
case "html":
|
|
125
|
+
default: return this.renderErrorAsHTML(error, ctx);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
renderValidationError(error, ctx) {
|
|
129
|
+
switch (ctx.request.accepts([
|
|
130
|
+
"html",
|
|
131
|
+
"application/vnd.api+json",
|
|
132
|
+
"json"
|
|
133
|
+
])) {
|
|
134
|
+
case "application/vnd.api+json": return this.renderValidationErrorAsJSONAPI(error, ctx);
|
|
135
|
+
case "json": return this.renderValidationErrorAsJSON(error, ctx);
|
|
136
|
+
case "html":
|
|
137
|
+
default: return this.renderValidationErrorAsHTML(error, ctx);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
async report(error, ctx) {
|
|
141
|
+
const httpError = this.toHttpError(error);
|
|
142
|
+
if (!this.shouldReport(httpError)) return;
|
|
143
|
+
if (typeof httpError.report === "function") {
|
|
144
|
+
httpError.report(httpError, ctx);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const level = this.getErrorLogLevel(httpError);
|
|
148
|
+
ctx.logger.log(level, {
|
|
149
|
+
...level === "error" || level === "fatal" ? { err: httpError } : {},
|
|
150
|
+
...this.context(ctx)
|
|
151
|
+
}, httpError.message);
|
|
152
|
+
}
|
|
153
|
+
async handle(error, ctx) {
|
|
154
|
+
const httpError = this.toHttpError(error);
|
|
155
|
+
if (typeof httpError.handle === "function") return httpError.handle(httpError, ctx);
|
|
156
|
+
if (httpError.code === "E_VALIDATION_ERROR" && "messages" in httpError) return this.renderValidationError(httpError, ctx);
|
|
157
|
+
return this.renderError(httpError, ctx);
|
|
158
|
+
}
|
|
378
159
|
};
|
|
160
|
+
export { BriskRoute, CookieClient, CookieParser, CookieSerializer, ExceptionHandler, HttpContext, HttpRequest, HttpResponse, Qs, Redirect, ResponseStatus, Route, RouteGroup, RouteResource, Router, Server, defineConfig, errors_exports as errors, tracing_channels_exports as tracingChannels };
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
createURL,
|
|
6
|
-
findRoute
|
|
7
|
-
} from "../../chunk-2QM3D5BN.js";
|
|
8
|
-
export {
|
|
9
|
-
createURL,
|
|
10
|
-
createUrlBuilder,
|
|
11
|
-
findRoute
|
|
12
|
-
};
|
|
1
|
+
import { n as findRoute, t as createURL } from "../../helpers-C_2HouOe.js";
|
|
2
|
+
import { t as createUrlBuilder } from "../../url_builder-piNQy-CF.js";
|
|
3
|
+
export { createURL, createUrlBuilder, findRoute };
|
package/build/src/debug.d.ts
CHANGED
|
@@ -66,6 +66,13 @@ export declare class ExceptionHandler extends Macroable {
|
|
|
66
66
|
* Errors with these codes are handled but not logged
|
|
67
67
|
*/
|
|
68
68
|
protected ignoreCodes: string[];
|
|
69
|
+
/**
|
|
70
|
+
* Normalizes any thrown value into a standardized HttpError object
|
|
71
|
+
* Ensures the error has required properties like message and status
|
|
72
|
+
* @param error - Any thrown value (Error, string, object, etc.)
|
|
73
|
+
* @returns {HttpError} Normalized error object with status and message
|
|
74
|
+
*/
|
|
75
|
+
protected toHttpError(error: unknown): HttpError;
|
|
69
76
|
/**
|
|
70
77
|
* Provides additional context information for error reporting
|
|
71
78
|
* Includes request ID when available for correlation across logs
|
package/build/src/helpers.d.ts
CHANGED
package/build/src/helpers.js
CHANGED
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
default as default2,
|
|
5
|
-
default2 as default3,
|
|
6
|
-
matchRoute,
|
|
7
|
-
middlewareInfo,
|
|
8
|
-
parseRoute,
|
|
9
|
-
routeInfo,
|
|
10
|
-
serializeCookie
|
|
11
|
-
} from "../chunk-QDK57QGB.js";
|
|
12
|
-
import {
|
|
13
|
-
createURL
|
|
14
|
-
} from "../chunk-2QM3D5BN.js";
|
|
15
|
-
export {
|
|
16
|
-
appendQueryString,
|
|
17
|
-
createSignedURL,
|
|
18
|
-
createURL,
|
|
19
|
-
default2 as encodeUrl,
|
|
20
|
-
matchRoute,
|
|
21
|
-
middlewareInfo,
|
|
22
|
-
default3 as mime,
|
|
23
|
-
parseRoute,
|
|
24
|
-
routeInfo,
|
|
25
|
-
serializeCookie
|
|
26
|
-
};
|
|
1
|
+
import { a as middlewareInfo, c as routeInfo, i as matchRoute, l as serializeCookie, n as createSignedURL, o as mime, r as encodeUrl, s as parseRoute, t as appendQueryString } from "../helpers-oKG4uNSM.js";
|
|
2
|
+
import { t as createURL } from "../helpers-C_2HouOe.js";
|
|
3
|
+
export { appendQueryString, createSignedURL, createURL, encodeUrl, matchRoute, middlewareInfo, mime, parseRoute, routeInfo, serializeCookie };
|