Browse Source

Merge pull request #381 from repodio/throw-on-cancel-android

Cancel download throw error bugfix (Android)
Travis Nuttall 5 years ago
parent
commit
104a94e3a9
No account linked to committer's email address
1 changed files with 7 additions and 0 deletions
  1. 7
    0
      index.js

+ 7
- 0
index.js View File

228
     return fetchFile(options, method, url, headers, body)
228
     return fetchFile(options, method, url, headers, body)
229
   }
229
   }
230
 
230
 
231
+  let promiseResolve;
232
+  let promiseReject;
233
+
231
   // from remote HTTP(S)
234
   // from remote HTTP(S)
232
   let promise = new Promise((resolve, reject) => {
235
   let promise = new Promise((resolve, reject) => {
236
+    promiseResolve = resolve;
237
+    promiseReject = reject;
238
+
233
     let nativeMethodName = Array.isArray(body) ? 'fetchBlobForm' : 'fetchBlob'
239
     let nativeMethodName = Array.isArray(body) ? 'fetchBlobForm' : 'fetchBlob'
234
 
240
 
235
     // on progress event listener
241
     // on progress event listener
370
     subscriptionUpload.remove()
376
     subscriptionUpload.remove()
371
     stateEvent.remove()
377
     stateEvent.remove()
372
     RNFetchBlob.cancelRequest(taskId, fn)
378
     RNFetchBlob.cancelRequest(taskId, fn)
379
+    promiseReject(new Error("canceled"))
373
   }
380
   }
374
   promise.taskId = taskId
381
   promise.taskId = taskId
375
 
382