@nxtedition/lib 15.0.40 → 15.0.42
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 +16 -6
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -45,6 +45,10 @@ module.exports.request = async function request(ctx, next) {
|
|
|
45
45
|
ctx.method = req.method
|
|
46
46
|
ctx.query = ctx.url.search ? querystring.parse(ctx.url.search.slice(1)) : {}
|
|
47
47
|
|
|
48
|
+
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
49
|
+
req.resume() // Dump the body if there is one.
|
|
50
|
+
}
|
|
51
|
+
|
|
48
52
|
res.setHeader('request-id', req.id)
|
|
49
53
|
|
|
50
54
|
const isHealthcheck = ctx.url.pathname === '/healthcheck'
|
|
@@ -87,6 +91,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
87
91
|
reqLogger.trace('request completed')
|
|
88
92
|
}
|
|
89
93
|
} catch (err) {
|
|
94
|
+
const reason = ac.signal.reason
|
|
90
95
|
const responseTime = Math.round(performance.now() - startTime)
|
|
91
96
|
|
|
92
97
|
req.on('error', (err) => {
|
|
@@ -99,7 +104,7 @@ module.exports.request = async function request(ctx, next) {
|
|
|
99
104
|
reqLogger.warn({ err }, 'request error')
|
|
100
105
|
})
|
|
101
106
|
|
|
102
|
-
if (!
|
|
107
|
+
if (!res.headersSent && !res.destroyed) {
|
|
103
108
|
res.statusCode = err.statusCode || 500
|
|
104
109
|
|
|
105
110
|
let reqId = req?.id || err.id
|
|
@@ -127,7 +132,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
127
132
|
res.write(JSON.stringify(err.body))
|
|
128
133
|
}
|
|
129
134
|
|
|
130
|
-
reqLogger = reqLogger.child({ res, err, responseTime })
|
|
135
|
+
reqLogger = reqLogger.child({ res, err, reason, responseTime })
|
|
136
|
+
|
|
131
137
|
if (res.statusCode < 500) {
|
|
132
138
|
reqLogger.warn('request failed')
|
|
133
139
|
} else {
|
|
@@ -138,7 +144,8 @@ module.exports.request = async function request(ctx, next) {
|
|
|
138
144
|
|
|
139
145
|
res.end()
|
|
140
146
|
} else {
|
|
141
|
-
reqLogger = reqLogger.child({ res, err, responseTime })
|
|
147
|
+
reqLogger = reqLogger.child({ res, err, reason, responseTime })
|
|
148
|
+
|
|
142
149
|
if (req.aborted || err.name === 'AbortError') {
|
|
143
150
|
reqLogger.debug('request aborted')
|
|
144
151
|
} else if (err.statusCode < 500) {
|
|
@@ -147,9 +154,12 @@ module.exports.request = async function request(ctx, next) {
|
|
|
147
154
|
reqLogger.error('request error')
|
|
148
155
|
}
|
|
149
156
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
157
|
+
if (res.writableEnded) {
|
|
158
|
+
reqLogger.debug('response completed')
|
|
159
|
+
} else {
|
|
160
|
+
reqLogger.debug('response destroyed')
|
|
161
|
+
res.destroy()
|
|
162
|
+
}
|
|
153
163
|
}
|
|
154
164
|
}
|
|
155
165
|
}
|