Skip to content

Commit e20ffea

Browse files
Capture error message, otherwise capture cause of HTTP failure (#358)
* Capture error message, otherwise capture cause of HTTP failure One approach to #356 * Comment to clarify what 'response' might be Addressing #356 with a comment, since this is a type issue * Improvement of performance, readability, and priority in failure case Moving forward on #358 with a bit more aggressive change per discussion
1 parent 26fb0e1 commit e20ffea

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/nano.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,18 @@ module.exports = exports = function dbScope (cfg) {
122122
}
123123
}
124124

125-
// let parsed
126-
const responseHeaders = Object.assign({
125+
const responseHeaders = {
127126
uri: scrubURL(req.url),
128-
statusCode
129-
}, response.headers ? response.headers : {})
127+
statusCode,
128+
...(response.headers ?? {})
129+
};
130+
130131
if (!response.status) {
131-
response.statusText = response.cause.toString()
132132
log({ err: 'socket', body, headers: responseHeaders })
133133
if (reject) {
134-
reject(new Error(`error happened in your connection. Reason: ${response.statusText}`))
134+
// since #relax might have sent Error rather than Response:
135+
const statusText = response.cause?.toString() ?? response.message
136+
reject(new Error(`error happened in your connection. Reason: ${statusText}`))
135137
}
136138
return
137139
}

0 commit comments

Comments
 (0)