@nxtedition/lib 21.0.13 → 21.0.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/http.js +13 -11
- package/package.json +1 -1
- package/serializers.js +2 -1
package/http.js
CHANGED
|
@@ -27,6 +27,14 @@ export function genReqId() {
|
|
|
27
27
|
let reqTimeoutError
|
|
28
28
|
let resTimeoutError
|
|
29
29
|
|
|
30
|
+
function onRequestTimeout() {
|
|
31
|
+
this.destroy((reqTimeoutError ??= new createError.RequestTimeout()))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function onResponseTimeout() {
|
|
35
|
+
this.destroy((resTimeoutError ??= new createError.RequestTimeout()))
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
export async function request(ctx, next) {
|
|
31
39
|
const { req, res, logger } = ctx
|
|
32
40
|
const startTime = performance.now()
|
|
@@ -75,24 +83,18 @@ export async function request(ctx, next) {
|
|
|
75
83
|
await Promise.all([
|
|
76
84
|
next(),
|
|
77
85
|
new Promise((resolve, reject) => {
|
|
78
|
-
req
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
.on('error', function (err) {
|
|
83
|
-
this.log.error({ err }, 'request error')
|
|
84
|
-
})
|
|
86
|
+
req.on('timeout', onRequestTimeout).on('error', function (err) {
|
|
87
|
+
reject(err)
|
|
88
|
+
})
|
|
85
89
|
res
|
|
86
|
-
.on('timeout',
|
|
87
|
-
this.destroy((resTimeoutError ??= new createError.RequestTimeout()))
|
|
88
|
-
})
|
|
90
|
+
.on('timeout', onResponseTimeout)
|
|
89
91
|
.on('error', function (err) {
|
|
90
92
|
reject(err)
|
|
91
93
|
})
|
|
92
94
|
// TODO (fix): Use 'end' once we can trust that
|
|
93
95
|
// 'end' or 'error' will always be emitted.
|
|
94
96
|
.on('close', function () {
|
|
95
|
-
|
|
97
|
+
this.log.debug('request closed')
|
|
96
98
|
resolve(null)
|
|
97
99
|
ac.abort()
|
|
98
100
|
})
|
package/package.json
CHANGED
package/serializers.js
CHANGED
|
@@ -192,6 +192,7 @@ function errSerializer(err) {
|
|
|
192
192
|
const _err = Object.create(pinoErrProto)
|
|
193
193
|
_err.type =
|
|
194
194
|
toString.call(err.constructor) === '[object Function]' ? err.constructor.name : err.name
|
|
195
|
+
_err.name = err.name
|
|
195
196
|
_err.message = err.message
|
|
196
197
|
_err.stack = err.stack
|
|
197
198
|
|
|
@@ -210,7 +211,7 @@ function errSerializer(err) {
|
|
|
210
211
|
if (!Object.prototype.hasOwnProperty.call(val, seen)) {
|
|
211
212
|
_err[key] = errSerializer(val)
|
|
212
213
|
}
|
|
213
|
-
} else if (val != null &&
|
|
214
|
+
} else if (val != null && !/^[A-Z0-9_]+$/.test(key)) {
|
|
214
215
|
_err[key] = val
|
|
215
216
|
}
|
|
216
217
|
}
|