Skip to content

Commit

Permalink
Follow-up to cd11a50
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Nov 22, 2019
1 parent cd11a50 commit 2c5d0c0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions source/request-as-event-emitter.ts
Expand Up @@ -159,6 +159,16 @@ export default (options: NormalizedOptions) => {
}
};

const attachErrorHandler = () => {
request.once('error', error => {
if (isAborted() && !(error instanceof TimedOutTimeoutError)) {
return;
}

onError(error);
});
};

try {
timer(request);
timedOut(request, options.timeout, options.url);
Expand All @@ -174,13 +184,7 @@ export default (options: NormalizedOptions) => {
request
);

request.once('error', error => {
if (isAborted() && !(error instanceof TimedOutTimeoutError)) {
return;
}

onError(error);
});
attachErrorHandler();

request.emit('upload-complete');
} catch (error) {
Expand All @@ -190,6 +194,9 @@ export default (options: NormalizedOptions) => {
}

onError(error);

// Handle future errors
attachErrorHandler();
}
};

Expand Down

0 comments on commit 2c5d0c0

Please sign in to comment.