Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 57a28e1

Browse files
committed
Add Android Download Manager status code handling and improve error message #297
1 parent 221287d commit 57a28e1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ public void readStream(String path, String encoding, int bufferSize, int tick, f
234234

235235
InputStream fs;
236236
if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
237-
fs = RNFetchBlob.RCTContext.getAssets().open(path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, ""));
237+
fs = RNFetchBlob.RCTContext.getAssets()
238+
.open(path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, ""));
238239
}
239240
else {
240241
fs = new FileInputStream(new File(path));

android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,17 @@ public void onReceive(Context context, Intent intent) {
629629
DownloadManager dm = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
630630
dm.query(query);
631631
Cursor c = dm.query(query);
632-
String error = null;
632+
633+
633634
String filePath = null;
634635
// the file exists in media content database
635636
if (c.moveToFirst()) {
637+
// #297 handle failed request
638+
int statusCode = c.getInt(c.getColumnIndex(DownloadManager.COLUMN_STATUS));
639+
if(statusCode == DownloadManager.STATUS_FAILED) {
640+
this.callback.invoke("Download manager failed to download from " + this.url + ". Statu Code = " + statusCode, null, null);
641+
return;
642+
}
636643
String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
637644
Uri uri = Uri.parse(contentUri);
638645
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
@@ -653,7 +660,8 @@ public void onReceive(Context context, Intent intent) {
653660
this.callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, customDest);
654661

655662
} catch(Exception ex) {
656-
error = ex.getLocalizedMessage();
663+
ex.printStackTrace();
664+
this.callback.invoke(ex.getLocalizedMessage(), null);
657665
}
658666
}
659667
else {

0 commit comments

Comments
 (0)