itinance/react-native-fs

Poor/empty exception messages on Android

Open

#63 opened on Mar 19, 2016

View on GitHub
 (0 comments) (0 reactions) (0 assignees)C# (4,629 stars) (919 forks)batch import
help wanted

Description

I struggled to fix the download correctness issue in PR #62 due to the JS error messages being empty on Android. (We were just getting an empty Error object.)

Ideally JS errors and/or logging should provide information from the Java exception. As a quick hack, the below change to RNFSManager.java helped a lot. It turned out to be an HTTP 404 error and was easy to fix after knowing the issue.

I'm not submitting this as a pull request just yet because I suspect react-native may already provide a built-in Exception-to-JS-Error conversion utility function - any thoughts from RN Android devs?

private WritableMap makeErrorPayload(Exception ex) { WritableMap error = Arguments.createMap();

// https://stackoverflow.com/questions/7242596/e-printstacktrace-in-string
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
String s = writer.toString();

//error.putString("message", ex.getMessage());
error.putString("message", s);
// TODO: Consolidate and move ex.printStackTrace() here?

return error;

}

Contributor guide