@adonisjs/http-server 6.8.2-9 → 7.0.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.
Files changed (107) hide show
  1. package/build/chunk-XX72ATFY.js +4388 -0
  2. package/build/factories/main.d.ts +149 -6
  3. package/build/factories/main.js +331 -14
  4. package/build/index.d.ts +272 -14
  5. package/build/index.js +308 -22
  6. package/build/{src/server/main.d.ts → main-29eaaee4.d.ts} +12 -17
  7. package/build/main-e5b46c83.d.ts +2210 -0
  8. package/build/src/types/main.d.ts +14 -7
  9. package/build/src/types/main.js +0 -15
  10. package/package.json +62 -53
  11. package/build/factories/http_context.d.ts +0 -25
  12. package/build/factories/http_context.js +0 -51
  13. package/build/factories/http_server.d.ts +0 -8
  14. package/build/factories/http_server.js +0 -26
  15. package/build/factories/qs_parser_factory.d.ts +0 -20
  16. package/build/factories/qs_parser_factory.js +0 -44
  17. package/build/factories/request.d.ts +0 -29
  18. package/build/factories/request.js +0 -73
  19. package/build/factories/response.d.ts +0 -29
  20. package/build/factories/response.js +0 -77
  21. package/build/factories/router.d.ts +0 -23
  22. package/build/factories/router.js +0 -45
  23. package/build/factories/server_factory.d.ts +0 -29
  24. package/build/factories/server_factory.js +0 -65
  25. package/build/src/cookies/client.d.ts +0 -37
  26. package/build/src/cookies/client.js +0 -84
  27. package/build/src/cookies/drivers/encrypted.d.ts +0 -16
  28. package/build/src/cookies/drivers/encrypted.js +0 -36
  29. package/build/src/cookies/drivers/plain.d.ts +0 -15
  30. package/build/src/cookies/drivers/plain.js +0 -33
  31. package/build/src/cookies/drivers/signed.d.ts +0 -16
  32. package/build/src/cookies/drivers/signed.js +0 -36
  33. package/build/src/cookies/parser.d.ts +0 -37
  34. package/build/src/cookies/parser.js +0 -167
  35. package/build/src/cookies/serializer.d.ts +0 -33
  36. package/build/src/cookies/serializer.js +0 -79
  37. package/build/src/debug.d.ts +0 -3
  38. package/build/src/debug.js +0 -10
  39. package/build/src/define_config.d.ts +0 -5
  40. package/build/src/define_config.js +0 -51
  41. package/build/src/define_middleware.d.ts +0 -11
  42. package/build/src/define_middleware.js +0 -35
  43. package/build/src/exception_handler.d.ts +0 -112
  44. package/build/src/exception_handler.js +0 -303
  45. package/build/src/exceptions.d.ts +0 -84
  46. package/build/src/exceptions.js +0 -38
  47. package/build/src/helpers.d.ts +0 -23
  48. package/build/src/helpers.js +0 -84
  49. package/build/src/http_context/local_storage.d.ts +0 -12
  50. package/build/src/http_context/local_storage.js +0 -39
  51. package/build/src/http_context/main.d.ts +0 -58
  52. package/build/src/http_context/main.js +0 -105
  53. package/build/src/qs.d.ts +0 -11
  54. package/build/src/qs.js +0 -25
  55. package/build/src/redirect.d.ts +0 -42
  56. package/build/src/redirect.js +0 -140
  57. package/build/src/request.d.ts +0 -565
  58. package/build/src/request.js +0 -865
  59. package/build/src/response.d.ts +0 -540
  60. package/build/src/response.js +0 -1208
  61. package/build/src/router/brisk.d.ts +0 -42
  62. package/build/src/router/brisk.js +0 -85
  63. package/build/src/router/executor.d.ts +0 -8
  64. package/build/src/router/executor.js +0 -29
  65. package/build/src/router/factories/use_return_value.d.ts +0 -6
  66. package/build/src/router/factories/use_return_value.js +0 -22
  67. package/build/src/router/group.d.ts +0 -65
  68. package/build/src/router/group.js +0 -207
  69. package/build/src/router/lookup_store/main.d.ts +0 -49
  70. package/build/src/router/lookup_store/main.js +0 -86
  71. package/build/src/router/lookup_store/route_finder.d.ts +0 -21
  72. package/build/src/router/lookup_store/route_finder.js +0 -49
  73. package/build/src/router/lookup_store/url_builder.d.ts +0 -52
  74. package/build/src/router/lookup_store/url_builder.js +0 -209
  75. package/build/src/router/main.d.ts +0 -128
  76. package/build/src/router/main.js +0 -316
  77. package/build/src/router/matchers.d.ts +0 -27
  78. package/build/src/router/matchers.js +0 -36
  79. package/build/src/router/parser.d.ts +0 -5
  80. package/build/src/router/parser.js +0 -17
  81. package/build/src/router/resource.d.ts +0 -54
  82. package/build/src/router/resource.js +0 -216
  83. package/build/src/router/route.d.ts +0 -92
  84. package/build/src/router/route.js +0 -293
  85. package/build/src/router/store.d.ts +0 -66
  86. package/build/src/router/store.js +0 -195
  87. package/build/src/server/factories/final_handler.d.ts +0 -9
  88. package/build/src/server/factories/final_handler.js +0 -30
  89. package/build/src/server/factories/middleware_handler.d.ts +0 -8
  90. package/build/src/server/factories/middleware_handler.js +0 -16
  91. package/build/src/server/factories/write_response.d.ts +0 -6
  92. package/build/src/server/factories/write_response.js +0 -24
  93. package/build/src/server/main.js +0 -283
  94. package/build/src/types/base.d.ts +0 -19
  95. package/build/src/types/base.js +0 -9
  96. package/build/src/types/middleware.d.ts +0 -35
  97. package/build/src/types/middleware.js +0 -9
  98. package/build/src/types/qs.d.ts +0 -68
  99. package/build/src/types/qs.js +0 -9
  100. package/build/src/types/request.d.ts +0 -39
  101. package/build/src/types/request.js +0 -9
  102. package/build/src/types/response.d.ts +0 -45
  103. package/build/src/types/response.js +0 -9
  104. package/build/src/types/route.d.ts +0 -165
  105. package/build/src/types/route.js +0 -9
  106. package/build/src/types/server.d.ts +0 -72
  107. package/build/src/types/server.js +0 -9
@@ -1,79 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import cookie from 'cookie';
10
- import string from '@poppinss/utils/string';
11
- import { CookieClient } from './client.js';
12
- /**
13
- * Cookies serializer is used to serialize a value to be set on the `Set-Cookie`
14
- * header. You can `encode`, `sign` on `encrypt` cookies using the serializer
15
- * and then set them individually using the `set-cookie` header.
16
- */
17
- export class CookieSerializer {
18
- #client;
19
- constructor(encryption) {
20
- this.#client = new CookieClient(encryption);
21
- }
22
- /**
23
- * Serializes the key-value pair to a string, that can be set on the
24
- * `Set-Cookie` header.
25
- */
26
- #serializeAsCookie(key, value, options) {
27
- /**
28
- * Invoked expires method to get the date
29
- */
30
- let expires = options?.expires;
31
- if (typeof expires === 'function') {
32
- expires = expires();
33
- }
34
- /**
35
- * Parse string based max age to seconds
36
- */
37
- let maxAge = options?.maxAge ? string.seconds.parse(options?.maxAge) : undefined;
38
- const parsedOptions = Object.assign({}, options, { maxAge, expires });
39
- return cookie.serialize(key, value, parsedOptions);
40
- }
41
- /**
42
- * Encodes value as a plain cookie. By default, the plain value will be converted
43
- * to a string using "JSON.stringify" method and then encoded as a base64 string.
44
- *
45
- * You can disable encoding of the cookie by setting `options.encoded = false`.
46
- *
47
- * ```ts
48
- * serializer.encode('name', 'virk')
49
- * ```
50
- */
51
- encode(key, value, options) {
52
- const packedValue = options?.encode === false ? value : this.#client.encode(key, value);
53
- if (packedValue === null || packedValue === undefined) {
54
- return null;
55
- }
56
- return this.#serializeAsCookie(key, packedValue, options);
57
- }
58
- /**
59
- * Sign a key-value pair to a signed cookie. The signed value has a
60
- * verification hash attached to it to detect data tampering.
61
- */
62
- sign(key, value, options) {
63
- const packedValue = this.#client.sign(key, value);
64
- if (packedValue === null) {
65
- return null;
66
- }
67
- return this.#serializeAsCookie(key, packedValue, options);
68
- }
69
- /**
70
- * Encrypts a key-value pair to an encrypted cookie.
71
- */
72
- encrypt(key, value, options) {
73
- const packedValue = this.#client.encrypt(key, value);
74
- if (packedValue === null) {
75
- return null;
76
- }
77
- return this.#serializeAsCookie(key, packedValue, options);
78
- }
79
- }
@@ -1,3 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- declare const _default: import("util").DebugLogger;
3
- export default _default;
@@ -1,10 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { debuglog } from 'node:util';
10
- export default debuglog('adonisjs:http');
@@ -1,5 +0,0 @@
1
- import type { ServerConfig } from './types/server.js';
2
- /**
3
- * Define configuration for the HTTP server
4
- */
5
- export declare function defineConfig(config: Partial<ServerConfig>): ServerConfig;
@@ -1,51 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import proxyAddr from 'proxy-addr';
10
- import string from '@poppinss/utils/string';
11
- /**
12
- * Define configuration for the HTTP server
13
- */
14
- export function defineConfig(config) {
15
- const normalizedConfig = {
16
- allowMethodSpoofing: false,
17
- trustProxy: proxyAddr.compile('loopback'),
18
- subdomainOffset: 2,
19
- generateRequestId: false,
20
- useAsyncLocalStorage: false,
21
- etag: false,
22
- jsonpCallbackName: 'callback',
23
- cookie: {
24
- maxAge: '2h',
25
- path: '/',
26
- httpOnly: true,
27
- secure: false,
28
- sameSite: false,
29
- },
30
- qs: {
31
- parse: {
32
- depth: 5,
33
- parameterLimit: 1000,
34
- allowSparse: false,
35
- arrayLimit: 20,
36
- comma: true,
37
- },
38
- stringify: {
39
- encode: true,
40
- encodeValuesOnly: false,
41
- arrayFormat: 'indices',
42
- skipNulls: false,
43
- },
44
- },
45
- ...config,
46
- };
47
- if (normalizedConfig.cookie.maxAge) {
48
- normalizedConfig.cookie.maxAge = string.seconds.parse(normalizedConfig.cookie.maxAge);
49
- }
50
- return normalizedConfig;
51
- }
@@ -1,11 +0,0 @@
1
- import type { LazyImport, UnWrapLazyImport } from './types/base.js';
2
- import type { GetMiddlewareArgs, MiddlewareAsClass, ParsedGlobalMiddleware } from './types/middleware.js';
3
- /**
4
- * Define an collection of named middleware. The collection gets converted
5
- * into a collection of factory functions. Calling the function returns
6
- * a reference to the executable middleware.
7
- */
8
- export declare function defineNamedMiddleware<NamedMiddleware extends Record<string | number | symbol, LazyImport<MiddlewareAsClass>>>(collection: NamedMiddleware): { [K in keyof NamedMiddleware]: <Args extends GetMiddlewareArgs<UnWrapLazyImport<NamedMiddleware[K]>>>(...args: Args) => {
9
- name: K;
10
- args: Args[0];
11
- } & ParsedGlobalMiddleware; };
@@ -1,35 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import { moduleImporter } from '@adonisjs/fold';
10
- /**
11
- * Converts a middleware name and its lazy import to a factory function. The function
12
- * can than later be used to reference the middleware with different arguments
13
- * every time.
14
- */
15
- function middlewareReferenceBuilder(name, middleware) {
16
- const handler = moduleImporter(middleware, 'handle').toHandleMethod();
17
- return function (...args) {
18
- return {
19
- name,
20
- args: args[0],
21
- ...handler,
22
- };
23
- };
24
- }
25
- /**
26
- * Define an collection of named middleware. The collection gets converted
27
- * into a collection of factory functions. Calling the function returns
28
- * a reference to the executable middleware.
29
- */
30
- export function defineNamedMiddleware(collection) {
31
- return Object.keys(collection).reduce((result, key) => {
32
- result[key] = middlewareReferenceBuilder(key, collection[key]);
33
- return result;
34
- }, {});
35
- }
@@ -1,112 +0,0 @@
1
- import type { Level } from '@adonisjs/logger/types';
2
- import type { HttpContext } from './http_context/main.js';
3
- import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
4
- /**
5
- * The base HTTP exception handler one can inherit from to handle
6
- * HTTP exceptions.
7
- *
8
- * The HTTP exception handler has support for
9
- *
10
- * - Ability to render exceptions by calling the render method on the exception.
11
- * - Rendering status pages
12
- * - Pretty printing errors during development
13
- * - Transforming errors to JSON or HTML using content negotiation
14
- * - Reporting errors
15
- */
16
- export declare class ExceptionHandler {
17
- #private;
18
- /**
19
- * Whether or not to render debug info. When set to true, the errors
20
- * will have the complete error stack.
21
- */
22
- protected debug: boolean;
23
- /**
24
- * Whether or not to render status pages. When set to true, the unhandled
25
- * errors with matching status codes will be rendered using a status
26
- * page.
27
- */
28
- protected renderStatusPages: boolean;
29
- /**
30
- * A collection of error status code range and the view to render.
31
- */
32
- protected statusPages: Record<StatusPageRange, StatusPageRenderer>;
33
- /**
34
- * Enable/disable errors reporting
35
- */
36
- protected reportErrors: boolean;
37
- /**
38
- * An array of exception classes to ignore when
39
- * reporting an error
40
- */
41
- protected ignoreExceptions: any[];
42
- /**
43
- * An array of HTTP status codes to ignore when reporting
44
- * an error
45
- */
46
- protected ignoreStatuses: number[];
47
- /**
48
- * An array of error codes to ignore when reporting
49
- * an error
50
- */
51
- protected ignoreCodes: string[];
52
- /**
53
- * Error reporting context
54
- */
55
- protected context(ctx: HttpContext): any;
56
- /**
57
- * Renders an error to JSON response
58
- */
59
- protected renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
60
- /**
61
- * Renders an error to JSON API response
62
- */
63
- protected renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
64
- /**
65
- * Renders an error to HTML response
66
- */
67
- protected renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
68
- /**
69
- * Renders the validation error message to a JSON
70
- * response
71
- */
72
- protected renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
73
- /**
74
- * Renders the validation error message as per JSON API
75
- * spec
76
- */
77
- protected renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
78
- /**
79
- * Renders the validation error as an HTML string
80
- */
81
- protected renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
82
- /**
83
- * Renders the error to response
84
- */
85
- protected renderError(error: HttpError, ctx: HttpContext): Promise<void>;
86
- /**
87
- * Renders the validation error to response
88
- */
89
- protected renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
90
- /**
91
- * Returns the log level for an error based upon the error
92
- * status code.
93
- */
94
- protected getErrorLogLevel(error: HttpError): Level;
95
- /**
96
- * A boolean to control if errors should be rendered with
97
- * all the available debugging info.
98
- */
99
- protected isDebuggingEnabled(_: HttpContext): boolean;
100
- /**
101
- * Returns a boolean by checking if an error should be reported.
102
- */
103
- protected shouldReport(error: HttpError): boolean;
104
- /**
105
- * Reports an error during an HTTP request
106
- */
107
- report(error: unknown, ctx: HttpContext): Promise<void>;
108
- /**
109
- * Handles the error during the HTTP request.
110
- */
111
- handle(error: unknown, ctx: HttpContext): Promise<any>;
112
- }
@@ -1,303 +0,0 @@
1
- /*
2
- * @adonisjs/http-server
3
- *
4
- * (c) AdonisJS
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- import is from '@sindresorhus/is';
10
- import { parseRange } from './helpers.js';
11
- import * as errors from './exceptions.js';
12
- /**
13
- * The base HTTP exception handler one can inherit from to handle
14
- * HTTP exceptions.
15
- *
16
- * The HTTP exception handler has support for
17
- *
18
- * - Ability to render exceptions by calling the render method on the exception.
19
- * - Rendering status pages
20
- * - Pretty printing errors during development
21
- * - Transforming errors to JSON or HTML using content negotiation
22
- * - Reporting errors
23
- */
24
- export class ExceptionHandler {
25
- /**
26
- * Computed from the status pages property
27
- */
28
- #expandedStatusPages;
29
- /**
30
- * Whether or not to render debug info. When set to true, the errors
31
- * will have the complete error stack.
32
- */
33
- debug = process.env.NODE_ENV !== 'production';
34
- /**
35
- * Whether or not to render status pages. When set to true, the unhandled
36
- * errors with matching status codes will be rendered using a status
37
- * page.
38
- */
39
- renderStatusPages = process.env.NODE_ENV === 'production';
40
- /**
41
- * A collection of error status code range and the view to render.
42
- */
43
- statusPages = {};
44
- /**
45
- * Enable/disable errors reporting
46
- */
47
- reportErrors = true;
48
- /**
49
- * An array of exception classes to ignore when
50
- * reporting an error
51
- */
52
- ignoreExceptions = [
53
- errors.E_HTTP_EXCEPTION,
54
- errors.E_ROUTE_NOT_FOUND,
55
- errors.E_CANNOT_LOOKUP_ROUTE,
56
- errors.E_HTTP_REQUEST_ABORTED,
57
- ];
58
- /**
59
- * An array of HTTP status codes to ignore when reporting
60
- * an error
61
- */
62
- ignoreStatuses = [400, 422, 401];
63
- /**
64
- * An array of error codes to ignore when reporting
65
- * an error
66
- */
67
- ignoreCodes = [];
68
- /**
69
- * Expands status pages
70
- */
71
- #expandStatusPages() {
72
- if (!this.#expandedStatusPages) {
73
- this.#expandedStatusPages = Object.keys(this.statusPages).reduce((result, range) => {
74
- const renderer = this.statusPages[range];
75
- result = Object.assign(result, parseRange(range, renderer));
76
- return result;
77
- }, {});
78
- }
79
- return this.#expandedStatusPages;
80
- }
81
- /**
82
- * Forcefully tweaking the type of the error object to
83
- * have known properties.
84
- */
85
- #toHttpError(error) {
86
- const httpError = is.object(error) ? error : new Error(String(error));
87
- httpError.message = httpError.message || 'Internal server error';
88
- httpError.status = httpError.status || 500;
89
- return httpError;
90
- }
91
- /**
92
- * Error reporting context
93
- */
94
- context(ctx) {
95
- const requestId = ctx.request.id();
96
- return requestId
97
- ? {
98
- 'x-request-id': requestId,
99
- }
100
- : {};
101
- }
102
- /**
103
- * Renders an error to JSON response
104
- */
105
- async renderErrorAsJSON(error, ctx) {
106
- if (this.isDebuggingEnabled(ctx)) {
107
- const { default: Youch } = await import('youch');
108
- const json = await new Youch(error, ctx.request.request).toJSON();
109
- ctx.response.status(error.status).send(json.error);
110
- return;
111
- }
112
- ctx.response.status(error.status).send({ message: error.message });
113
- }
114
- /**
115
- * Renders an error to JSON API response
116
- */
117
- async renderErrorAsJSONAPI(error, ctx) {
118
- if (this.isDebuggingEnabled(ctx)) {
119
- const { default: Youch } = await import('youch');
120
- const json = await new Youch(error, ctx.request.request).toJSON();
121
- ctx.response.status(error.status).send(json.error);
122
- return;
123
- }
124
- ctx.response.status(error.status).send({
125
- errors: [
126
- {
127
- title: error.message,
128
- code: error.code,
129
- status: error.status,
130
- },
131
- ],
132
- });
133
- }
134
- /**
135
- * Renders an error to HTML response
136
- */
137
- async renderErrorAsHTML(error, ctx) {
138
- if (this.isDebuggingEnabled(ctx)) {
139
- const { default: Youch } = await import('youch');
140
- const html = await new Youch(error, ctx.request.request).toHTML();
141
- ctx.response.status(error.status).send(html);
142
- return;
143
- }
144
- ctx.response.status(error.status).send(`<p> ${error.message} </p>`);
145
- }
146
- /**
147
- * Renders the validation error message to a JSON
148
- * response
149
- */
150
- async renderValidationErrorAsJSON(error, ctx) {
151
- ctx.response.status(error.status).send({
152
- errors: error.messages,
153
- });
154
- }
155
- /**
156
- * Renders the validation error message as per JSON API
157
- * spec
158
- */
159
- async renderValidationErrorAsJSONAPI(error, ctx) {
160
- ctx.response.status(error.status).send({
161
- errors: error.messages.map((message) => {
162
- return {
163
- title: message.message,
164
- code: message.rule,
165
- source: {
166
- pointer: message.field,
167
- },
168
- meta: message.meta,
169
- };
170
- }),
171
- });
172
- }
173
- /**
174
- * Renders the validation error as an HTML string
175
- */
176
- async renderValidationErrorAsHTML(error, ctx) {
177
- ctx.response
178
- .status(error.status)
179
- .type('html')
180
- .send(error.messages
181
- .map((message) => {
182
- return `${message.field} - ${message.message}`;
183
- })
184
- .join('<br />'));
185
- }
186
- /**
187
- * Renders the error to response
188
- */
189
- renderError(error, ctx) {
190
- switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
191
- case 'application/vnd.api+json':
192
- return this.renderErrorAsJSONAPI(error, ctx);
193
- case 'json':
194
- return this.renderErrorAsJSON(error, ctx);
195
- case 'html':
196
- default:
197
- return this.renderErrorAsHTML(error, ctx);
198
- }
199
- }
200
- /**
201
- * Renders the validation error to response
202
- */
203
- renderValidationError(error, ctx) {
204
- switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
205
- case 'application/vnd.api+json':
206
- return this.renderValidationErrorAsJSONAPI(error, ctx);
207
- case 'json':
208
- return this.renderValidationErrorAsJSON(error, ctx);
209
- case 'html':
210
- default:
211
- return this.renderValidationErrorAsHTML(error, ctx);
212
- }
213
- }
214
- /**
215
- * Returns the log level for an error based upon the error
216
- * status code.
217
- */
218
- getErrorLogLevel(error) {
219
- if (error.status >= 500) {
220
- return 'error';
221
- }
222
- if (error.status >= 400) {
223
- return 'warn';
224
- }
225
- return 'info';
226
- }
227
- /**
228
- * A boolean to control if errors should be rendered with
229
- * all the available debugging info.
230
- */
231
- isDebuggingEnabled(_) {
232
- return this.debug;
233
- }
234
- /**
235
- * Returns a boolean by checking if an error should be reported.
236
- */
237
- shouldReport(error) {
238
- if (this.reportErrors === false) {
239
- return false;
240
- }
241
- if (this.ignoreStatuses.includes(error.status)) {
242
- return false;
243
- }
244
- if (error.code && this.ignoreCodes.includes(error.code)) {
245
- return false;
246
- }
247
- if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
248
- return false;
249
- }
250
- return true;
251
- }
252
- /**
253
- * Reports an error during an HTTP request
254
- */
255
- async report(error, ctx) {
256
- const httpError = this.#toHttpError(error);
257
- if (!this.shouldReport(httpError)) {
258
- return;
259
- }
260
- if (typeof httpError.report === 'function') {
261
- httpError.report(httpError, ctx);
262
- return;
263
- }
264
- /**
265
- * Log the error using the logger
266
- */
267
- const level = this.getErrorLogLevel(httpError);
268
- ctx.logger.log(level, {
269
- ...(level === 'error' || level === 'fatal' ? { err: httpError } : {}),
270
- ...this.context(ctx),
271
- }, httpError.message);
272
- }
273
- /**
274
- * Handles the error during the HTTP request.
275
- */
276
- async handle(error, ctx) {
277
- const httpError = this.#toHttpError(error);
278
- /**
279
- * Self handle exception
280
- */
281
- if (typeof httpError.handle === 'function') {
282
- return httpError.handle(httpError, ctx);
283
- }
284
- /**
285
- * Handle validation error using the validation error
286
- * renderers
287
- */
288
- if (httpError.code === 'E_VALIDATION_ERROR' && 'messages' in httpError) {
289
- return this.renderValidationError(httpError, ctx);
290
- }
291
- /**
292
- * Render status page
293
- */
294
- const statusPages = this.#expandStatusPages();
295
- if (this.renderStatusPages && statusPages[httpError.status]) {
296
- return statusPages[httpError.status](httpError, ctx);
297
- }
298
- /**
299
- * Use the format renderers.
300
- */
301
- return this.renderError(httpError, ctx);
302
- }
303
- }
@@ -1,84 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Exception } from '@poppinss/utils';
3
- import type { HttpContext } from './http_context/main.js';
4
- export declare const E_ROUTE_NOT_FOUND: new (args: [method: string, url: string], options?: ErrorOptions | undefined) => Exception;
5
- export declare const E_CANNOT_LOOKUP_ROUTE: new (args: [routeIdentifier: string], options?: ErrorOptions | undefined) => Exception;
6
- export declare const E_HTTP_EXCEPTION: {
7
- new (message?: string | undefined, options?: (ErrorOptions & {
8
- code?: string | undefined;
9
- status?: number | undefined;
10
- }) | undefined): {
11
- body: any;
12
- name: string;
13
- help?: string | undefined;
14
- code?: string | undefined;
15
- status: number;
16
- toString(): string;
17
- readonly [Symbol.toStringTag]: string;
18
- message: string;
19
- stack?: string | undefined;
20
- cause?: unknown;
21
- };
22
- code: string;
23
- /**
24
- * This method returns an instance of the exception class
25
- */
26
- invoke(body: any, status: number, code?: string): {
27
- body: any;
28
- name: string;
29
- help?: string | undefined;
30
- code?: string | undefined;
31
- status: number;
32
- toString(): string;
33
- readonly [Symbol.toStringTag]: string;
34
- message: string;
35
- stack?: string | undefined;
36
- cause?: unknown;
37
- };
38
- help?: string | undefined;
39
- status?: number | undefined;
40
- message?: string | undefined;
41
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
42
- prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
43
- stackTraceLimit: number;
44
- };
45
- export declare const E_HTTP_REQUEST_ABORTED: {
46
- new (message?: string | undefined, options?: (ErrorOptions & {
47
- code?: string | undefined;
48
- status?: number | undefined;
49
- }) | undefined): {
50
- handle(error: any, ctx: HttpContext): void;
51
- body: any;
52
- name: string;
53
- help?: string | undefined;
54
- code?: string | undefined;
55
- status: number;
56
- toString(): string;
57
- readonly [Symbol.toStringTag]: string;
58
- message: string;
59
- stack?: string | undefined;
60
- cause?: unknown;
61
- };
62
- code: string;
63
- /**
64
- * This method returns an instance of the exception class
65
- */
66
- invoke(body: any, status: number, code?: string): {
67
- body: any;
68
- name: string;
69
- help?: string | undefined;
70
- code?: string | undefined;
71
- status: number;
72
- toString(): string;
73
- readonly [Symbol.toStringTag]: string;
74
- message: string;
75
- stack?: string | undefined;
76
- cause?: unknown;
77
- };
78
- help?: string | undefined;
79
- status?: number | undefined;
80
- message?: string | undefined;
81
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
82
- prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
83
- stackTraceLimit: number;
84
- };