diff --git a/polyfill/Fetch.js b/polyfill/Fetch.js index c22fc0bf6..5b164ee86 100644 --- a/polyfill/Fetch.js +++ b/polyfill/Fetch.js @@ -59,10 +59,12 @@ class ReactNativeBlobUtilFetchPolyfill { // task.then is not, so we have to extend task.then with progress and // cancel function let progressHandler, uploadHandler, cancelHandler; + let scopedTask = null; let statefulPromise = promise .then((body) => { let task = RNconfig(config) .fetch(options.method, url, options.headers, body); + scopedTask = task; if (progressHandler) task.progress(progressHandler); if (uploadHandler) @@ -87,8 +89,8 @@ class ReactNativeBlobUtilFetchPolyfill { }; statefulPromise.cancel = () => { cancelHandler = true; - if (task.cancel) - task.cancel(); + if (scopedTask && scopedTask.cancel) + scopedTask.cancel(); }; return statefulPromise;