Skip to content

Commit

Permalink
fix: ignore request error if request is done
Browse files Browse the repository at this point in the history
  • Loading branch information
killagu committed Jun 28, 2022
1 parent 518d22c commit 94d7f5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/urllib.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,12 +1161,13 @@ function requestWithCallback(url, args, callback) {
});
}

var isRequestError = false;
var isRequestDone = false;
function handleRequestError(err) {
if (isRequestError || !err) {
console.log('req error: ', err);
if (isRequestDone || !err) {
return;
}
isRequestError = true;
isRequestDone = true;

if (err.name === 'Error') {
err.name = connected ? 'ResponseError' : 'RequestError';
Expand All @@ -1178,7 +1179,9 @@ function requestWithCallback(url, args, callback) {
debug('Request#%d pump args.stream to req', reqId);
pump(args.stream, req, handleRequestError);
} else {
req.end(body);
req.end(body, function () {
isRequestDone = true;
});
}
// when stream already consumed, req's `finish` event is emitted and pump will ignore error after pipe finished
// but if server response timeout later, we will abort the request and emit an error in req
Expand Down

0 comments on commit 94d7f5e

Please sign in to comment.