@nxtedition/lib 15.1.5 → 15.1.6
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 +36 -41
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -57,37 +57,42 @@ module.exports.request = async function request(ctx, next) {
|
|
|
57
57
|
reqLogger.trace('request started')
|
|
58
58
|
}
|
|
59
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
|
-
|
|
60
|
+
await Promise.all([
|
|
61
|
+
next(),
|
|
62
|
+
new Promise((resolve, reject) => {
|
|
63
|
+
req
|
|
64
|
+
.on('timeout', function () {
|
|
65
|
+
this.destroy(new createError.RequestTimeout())
|
|
66
|
+
})
|
|
67
|
+
.on('error', function (err) {
|
|
68
|
+
this.log.error({ err }, 'request error')
|
|
69
|
+
})
|
|
70
|
+
.on('end', function () {
|
|
71
|
+
this.log.trace('request end')
|
|
72
|
+
})
|
|
73
|
+
.on('close', function () {
|
|
74
|
+
this.log.trace('request close')
|
|
75
|
+
})
|
|
76
|
+
res
|
|
77
|
+
.on('timeout', function () {
|
|
78
|
+
this.destroy(new createError.RequestTimeout())
|
|
79
|
+
})
|
|
80
|
+
.on('error', function (err) {
|
|
81
|
+
this.log.error({ err }, 'response error')
|
|
82
|
+
})
|
|
83
|
+
.on('finish', function () {
|
|
84
|
+
this.log.trace('response finish')
|
|
85
|
+
})
|
|
86
|
+
.on('close', function () {
|
|
87
|
+
this.log.trace('response close')
|
|
88
|
+
if (this.errored) {
|
|
89
|
+
reject(this.errored)
|
|
90
|
+
} else {
|
|
91
|
+
resolve(null)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
}),
|
|
95
|
+
])
|
|
91
96
|
|
|
92
97
|
const responseTime = Math.round(performance.now() - startTime)
|
|
93
98
|
|
|
@@ -107,16 +112,6 @@ module.exports.request = async function request(ctx, next) {
|
|
|
107
112
|
} catch (err) {
|
|
108
113
|
const responseTime = Math.round(performance.now() - startTime)
|
|
109
114
|
|
|
110
|
-
req.on('error', (err) => {
|
|
111
|
-
if (res.statusCode > 500 || err.code !== 'ECONNRESET') {
|
|
112
|
-
reqLogger.warn({ err }, 'request error')
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
res.on('error', (err) => {
|
|
117
|
-
reqLogger.warn({ err }, 'request error')
|
|
118
|
-
})
|
|
119
|
-
|
|
120
115
|
if (!res.headersSent && !res.destroyed) {
|
|
121
116
|
res.statusCode = err.statusCode || 500
|
|
122
117
|
|