Skip to content

Commit

Permalink
[expo-file-system] Fix error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukmccall committed Apr 27, 2020
1 parent 77015a7 commit 9af4920
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 65 deletions.
Expand Up @@ -315,7 +315,7 @@ public void deleteAsync(String uriStr, Map<String, Object> options, Promise prom
if (options.containsKey("idempotent") && (Boolean) options.get("idempotent")) {
promise.resolve(null);
} else {
promise.reject("E_FILE_NOT_FOUND",
promise.reject("ERR_FILESYSTEM_CANNOT_FIND_FILE",
"File '" + uri + "' could not be deleted because it could not be found");
}
}
Expand All @@ -332,13 +332,13 @@ public void deleteAsync(String uriStr, Map<String, Object> options, Promise prom
public void moveAsync(Map<String, Object> options, Promise promise) {
try {
if (!options.containsKey("from")) {
promise.reject("E_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `from` path.");
promise.reject("ERR_FILESYSTEM_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `from` path.");
return;
}
Uri fromUri = Uri.parse((String) options.get("from"));
ensurePermission(Uri.withAppendedPath(fromUri, ".."), Permission.WRITE, "Location '" + fromUri + "' isn't movable.");
if (!options.containsKey("to")) {
promise.reject("E_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `to` path.");
promise.reject("ERR_FILESYSTEM_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `to` path.");
return;
}
Uri toUri = Uri.parse((String) options.get("to"));
Expand All @@ -350,7 +350,7 @@ public void moveAsync(Map<String, Object> options, Promise promise) {
if (from.renameTo(to)) {
promise.resolve(null);
} else {
promise.reject("E_FILE_NOT_MOVED",
promise.reject("ERR_FILESYSTEM_CANNOT_MOVE_FILE",
"File '" + fromUri + "' could not be moved to '" + toUri + "'");
}
} else {
Expand All @@ -366,13 +366,13 @@ public void moveAsync(Map<String, Object> options, Promise promise) {
public void copyAsync(Map<String, Object> options, Promise promise) {
try {
if (!options.containsKey("from")) {
promise.reject("E_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `from` path.");
promise.reject("ERR_FILESYSTEM_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `from` path.");
return;
}
Uri fromUri = Uri.parse((String) options.get("from"));
ensurePermission(fromUri, Permission.READ);
if (!options.containsKey("to")) {
promise.reject("E_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `to` path.");
promise.reject("ERR_FILESYSTEM_MISSING_PARAMETER", "`FileSystem.moveAsync` needs a `to` path.");
return;
}
Uri toUri = Uri.parse((String) options.get("to"));
Expand Down Expand Up @@ -420,7 +420,7 @@ public void makeDirectoryAsync(String uriStr, Map<String, Object> options, Promi
if (success || (setIntermediates && previouslyCreated)) {
promise.resolve(null);
} else {
promise.reject("E_DIRECTORY_NOT_CREATED",
promise.reject("ERR_FILESYSTEM_CANNOT_CREATE_DIRECTORY",
"Directory '" + uri + "' could not be created or already exists.");
}
} else {
Expand All @@ -447,7 +447,7 @@ public void readDirectoryAsync(String uriStr, Map<String, Object> options, Promi
}
promise.resolve(result);
} else {
promise.reject("E_DIRECTORY_NOT_READ",
promise.reject("ERR_FILESYSTEM_CANNOT_READ_DIRECTORY",
"Directory '" + uri + "' could not be read.");
}
} else {
Expand Down Expand Up @@ -545,7 +545,7 @@ public void getTotalDiskCapacityAsync(Promise promise) {
promise.resolve(capacityDouble);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
promise.reject("ERR_FILESYSTEM", "Unable to access total disk capacity", e);
promise.reject("ERR_FILESYSTEM_CANNOT_DETERMINE_DISK_CAPACITY", "Unable to access total disk capacity", e);
}
}

Expand All @@ -562,7 +562,7 @@ public void getFreeDiskStorageAsync(Promise promise) {
promise.resolve(storageDouble);
} catch (Exception e) {
Log.e(TAG, e.getMessage());
promise.reject("ERR_FILESYSTEM", "Unable to determine free disk storage capacity", e);
promise.reject("ERR_FILESYSTEM_CANNOT_DETERMINE_DISK_CAPACITY", "Unable to determine free disk storage capacity", e);
}
}

Expand All @@ -577,7 +577,7 @@ public void getContentUriAsync(String uri, Promise promise) {
File file = uriToFile(fileUri);
promise.resolve(contentUriFromFile(file).toString());
} else {
promise.reject("E_DIRECTORY_NOT_READ", "No readable files with the uri: " + uri + ". Please use other uri.");
promise.reject("ERR_FILESYSTEM_CANNOT_READ_DIRECTORY", "No readable files with the uri: " + uri + ". Please use other uri.");
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
Expand Down

0 comments on commit 9af4920

Please sign in to comment.