@adonisjs/http-server 6.8.2-11 → 6.8.2-12
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Macroable from '@poppinss/macroable';
|
|
1
2
|
import type { Level } from '@adonisjs/logger/types';
|
|
2
3
|
import type { HttpContext } from './http_context/main.js';
|
|
3
4
|
import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/server.js';
|
|
@@ -13,7 +14,7 @@ import type { HttpError, StatusPageRange, StatusPageRenderer } from './types/ser
|
|
|
13
14
|
* - Transforming errors to JSON or HTML using content negotiation
|
|
14
15
|
* - Reporting errors
|
|
15
16
|
*/
|
|
16
|
-
export declare class ExceptionHandler {
|
|
17
|
+
export declare class ExceptionHandler extends Macroable {
|
|
17
18
|
#private;
|
|
18
19
|
/**
|
|
19
20
|
* Whether or not to render debug info. When set to true, the errors
|
|
@@ -53,54 +54,54 @@ export declare class ExceptionHandler {
|
|
|
53
54
|
* Error reporting context
|
|
54
55
|
*/
|
|
55
56
|
protected context(ctx: HttpContext): any;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the log level for an error based upon the error
|
|
59
|
+
* status code.
|
|
60
|
+
*/
|
|
61
|
+
protected getErrorLogLevel(error: HttpError): Level;
|
|
62
|
+
/**
|
|
63
|
+
* A boolean to control if errors should be rendered with
|
|
64
|
+
* all the available debugging info.
|
|
65
|
+
*/
|
|
66
|
+
protected isDebuggingEnabled(_: HttpContext): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a boolean by checking if an error should be reported.
|
|
69
|
+
*/
|
|
70
|
+
protected shouldReport(error: HttpError): boolean;
|
|
56
71
|
/**
|
|
57
72
|
* Renders an error to JSON response
|
|
58
73
|
*/
|
|
59
|
-
|
|
74
|
+
renderErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
60
75
|
/**
|
|
61
76
|
* Renders an error to JSON API response
|
|
62
77
|
*/
|
|
63
|
-
|
|
78
|
+
renderErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
64
79
|
/**
|
|
65
80
|
* Renders an error to HTML response
|
|
66
81
|
*/
|
|
67
|
-
|
|
82
|
+
renderErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
68
83
|
/**
|
|
69
84
|
* Renders the validation error message to a JSON
|
|
70
85
|
* response
|
|
71
86
|
*/
|
|
72
|
-
|
|
87
|
+
renderValidationErrorAsJSON(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
73
88
|
/**
|
|
74
89
|
* Renders the validation error message as per JSON API
|
|
75
90
|
* spec
|
|
76
91
|
*/
|
|
77
|
-
|
|
92
|
+
renderValidationErrorAsJSONAPI(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
78
93
|
/**
|
|
79
94
|
* Renders the validation error as an HTML string
|
|
80
95
|
*/
|
|
81
|
-
|
|
96
|
+
renderValidationErrorAsHTML(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
82
97
|
/**
|
|
83
98
|
* Renders the error to response
|
|
84
99
|
*/
|
|
85
|
-
|
|
100
|
+
renderError(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
86
101
|
/**
|
|
87
102
|
* Renders the validation error to response
|
|
88
103
|
*/
|
|
89
|
-
|
|
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
|
+
renderValidationError(error: HttpError, ctx: HttpContext): Promise<void>;
|
|
104
105
|
/**
|
|
105
106
|
* Reports an error during an HTTP request
|
|
106
107
|
*/
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import is from '@sindresorhus/is';
|
|
10
|
+
import Macroable from '@poppinss/macroable';
|
|
10
11
|
import { parseRange } from './helpers.js';
|
|
11
12
|
import * as errors from './exceptions.js';
|
|
12
13
|
/**
|
|
@@ -21,7 +22,7 @@ import * as errors from './exceptions.js';
|
|
|
21
22
|
* - Transforming errors to JSON or HTML using content negotiation
|
|
22
23
|
* - Reporting errors
|
|
23
24
|
*/
|
|
24
|
-
export class ExceptionHandler {
|
|
25
|
+
export class ExceptionHandler extends Macroable {
|
|
25
26
|
/**
|
|
26
27
|
* Computed from the status pages property
|
|
27
28
|
*/
|
|
@@ -99,6 +100,44 @@ export class ExceptionHandler {
|
|
|
99
100
|
}
|
|
100
101
|
: {};
|
|
101
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Returns the log level for an error based upon the error
|
|
105
|
+
* status code.
|
|
106
|
+
*/
|
|
107
|
+
getErrorLogLevel(error) {
|
|
108
|
+
if (error.status >= 500) {
|
|
109
|
+
return 'error';
|
|
110
|
+
}
|
|
111
|
+
if (error.status >= 400) {
|
|
112
|
+
return 'warn';
|
|
113
|
+
}
|
|
114
|
+
return 'info';
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A boolean to control if errors should be rendered with
|
|
118
|
+
* all the available debugging info.
|
|
119
|
+
*/
|
|
120
|
+
isDebuggingEnabled(_) {
|
|
121
|
+
return this.debug;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns a boolean by checking if an error should be reported.
|
|
125
|
+
*/
|
|
126
|
+
shouldReport(error) {
|
|
127
|
+
if (this.reportErrors === false) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
if (this.ignoreStatuses.includes(error.status)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
if (error.code && this.ignoreCodes.includes(error.code)) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
if (this.ignoreExceptions.find((exception) => error instanceof exception)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
102
141
|
/**
|
|
103
142
|
* Renders an error to JSON response
|
|
104
143
|
*/
|
|
@@ -211,44 +250,6 @@ export class ExceptionHandler {
|
|
|
211
250
|
return this.renderValidationErrorAsHTML(error, ctx);
|
|
212
251
|
}
|
|
213
252
|
}
|
|
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
|
/**
|
|
253
254
|
* Reports an error during an HTTP request
|
|
254
255
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/http-server",
|
|
3
|
-
"version": "6.8.2-
|
|
3
|
+
"version": "6.8.2-12",
|
|
4
4
|
"description": "AdonisJS HTTP server with support packed with Routing and Cookies",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"@japa/assert": "^2.0.0-1",
|
|
59
59
|
"@japa/expect-type": "^2.0.0-0",
|
|
60
60
|
"@japa/runner": "^3.0.0-5",
|
|
61
|
-
"@swc/core": "^1.3.
|
|
61
|
+
"@swc/core": "^1.3.72",
|
|
62
62
|
"@types/accepts": "^1.3.5",
|
|
63
63
|
"@types/content-disposition": "^0.5.5",
|
|
64
64
|
"@types/cookie": "^0.5.1",
|
|
@@ -77,13 +77,13 @@
|
|
|
77
77
|
"@types/supertest": "^2.0.12",
|
|
78
78
|
"@types/type-is": "^1.6.3",
|
|
79
79
|
"@types/vary": "^1.1.0",
|
|
80
|
-
"@vinejs/vine": "^1.
|
|
80
|
+
"@vinejs/vine": "^1.6.0",
|
|
81
81
|
"autocannon": "^7.11.0",
|
|
82
82
|
"c8": "^8.0.1",
|
|
83
83
|
"cross-env": "^7.0.3",
|
|
84
84
|
"del-cli": "^5.0.0",
|
|
85
|
-
"eslint": "^8.
|
|
86
|
-
"fastify": "^4.
|
|
85
|
+
"eslint": "^8.46.0",
|
|
86
|
+
"fastify": "^4.21.0",
|
|
87
87
|
"fs-extra": "^11.1.1",
|
|
88
88
|
"get-port": "^7.0.0",
|
|
89
89
|
"github-label-sync": "^2.3.1",
|