Skip to content

Commit ea6e4d9

Browse files
committed
Android: two reject() calls did not have a code, iOS: slice() did not have code EISDIR, and "could not resolve URI" now is EINVAL everywhere
1 parent 54afd01 commit ea6e4d9

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public void onHostDestroy() {
132132
};
133133
RCTContext.addLifecycleEventListener(listener);
134134
} catch(Exception ex) {
135-
promise.reject(ex.getLocalizedMessage());
135+
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
136136
}
137137
}
138138

@@ -355,7 +355,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
355355
DownloadManager dm = (DownloadManager) RCTContext.getSystemService(RCTContext.DOWNLOAD_SERVICE);
356356
String path = RNFetchBlobFS.normalizePath(config.getString("path"));
357357
if(path == null) {
358-
promise.reject("RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"), "RNFetchblob.addCompleteDownload can not resolve URI:" + path);
358+
promise.reject("EINVAL", "RNFetchblob.addCompleteDownload can not resolve URI:" + + config.getString("path"));
359359
return;
360360
}
361361
try {
@@ -372,7 +372,7 @@ public void addCompleteDownload (ReadableMap config, Promise promise) {
372372
promise.resolve(null);
373373
}
374374
catch(Exception ex) {
375-
promise.reject("RNFetchblob.addCompleteDownload failed", ex.getStackTrace().toString());
375+
promise.reject("EUNSPECIFIED", ex.getLocalizedMessage());
376376
}
377377

378378
}

ios/RNFetchBlobFS.m

+11-3
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ + (void) readStream:(NSString *)uri
199199
}
200200
else
201201
{
202-
NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"code": @"ENOENT", @"detail": @"Unable to resolve URI" };
202+
NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"code": @"EINVAL", @"detail": @"Unable to resolve URI" };
203203
[event sendDeviceEventWithName:streamId body:payload];
204204
}
205205
// release buffer
@@ -759,10 +759,18 @@ + (void)slice:(NSString *)path
759759
NSFileManager * fm = [NSFileManager defaultManager];
760760
NSOutputStream * os = [[NSOutputStream alloc] initToFileAtPath:dest append:NO];
761761
[os open];
762-
// abort because the source file does not exist
763-
if([fm fileExistsAtPath:path] == NO) {
762+
763+
BOOL isDir = NO;
764+
BOOL exists = NO;
765+
exists = [fm fileExistsAtPath:path isDirectory: &isDir];
766+
767+
if (isDir) {
768+
return reject(@"EISDIR", [NSString stringWithFormat:@"Expecting a file but '%@' is a directory", path], nil);
769+
}
770+
if(!exists) {
764771
return reject(@"ENOENT", [NSString stringWithFormat: @"No such file '%@'", path ], nil);
765772
}
773+
766774
long size = [fm attributesOfItemAtPath:path error:nil].fileSize;
767775
long max = MIN(size, [end longValue]);
768776

0 commit comments

Comments
 (0)