diff --git a/ts/src/transports/fetch.ts b/ts/src/transports/fetch.ts index 230ba86a..d4c24104 100644 --- a/ts/src/transports/fetch.ts +++ b/ts/src/transports/fetch.ts @@ -44,6 +44,17 @@ class Fetch implements Transport { }); this.pump(this.reader, res); return; + }) + .catch(err => { + if (this.cancelled) { + this.options.debug && debug("Fetch.catch - request cancelled"); + return; + } + this.cancelled = true; + this.options.debug && debug("Fetch.catch", err.message); + detach(() => { + this.options.onEnd(err); + }); }); } @@ -69,6 +80,7 @@ class Fetch implements Transport { this.options.debug && debug("Fetch.catch - request cancelled"); return; } + this.cancelled = true; this.options.debug && debug("Fetch.catch", err.message); detach(() => { this.options.onEnd(err); @@ -89,6 +101,10 @@ class Fetch implements Transport { } cancel() { + if (this.cancelled) { + this.options.debug && debug("Fetch.abort.cancel already cancelled"); + return; + } this.cancelled = true; if (this.reader) { // If the reader has already been received in the pump then it can be cancelled immediately