Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add overload for a Promise's Reject method to allow objects/JObject to be sent #730

Closed
henningms opened this issue Oct 3, 2016 · 4 comments

Comments

@henningms
Copy link

In some instances it would be nice to be able to pass along a custom error object in the Reject method for a Promise/IPromise.

@rozele
Copy link
Collaborator

rozele commented Oct 3, 2016

@henningms we're just following the lead of what other platforms support for reject (e.g., there is no reject-with-error-object here https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java). You could, in the meantime, "resolve" the promise with the object and then trigger the error path from JavaScript.

@rozele
Copy link
Collaborator

rozele commented Oct 3, 2016

We could do something like this https://github.com/facebook/react-native/blob/d368ebfab2c389cc093f6a73e5c1021408cc6a73/React/Base/RCTUtils.m#L410, which shows how iOS adds a couple extra fields to the JS error object from the NSError, but it doesn't look like it supports and arbitrary custom error object.

@rozele
Copy link
Collaborator

rozele commented Oct 3, 2016

Scratch that last statement, the above link shows how iOS uses the NSError userInfo field (which generally is a dictionary) to support custom fields. I'll look and see how we can support something similar and how/if it's done on Android.

@rozele
Copy link
Collaborator

rozele commented Oct 3, 2016

Looks like it's not supported on Android (probably because Java Throwables do not have the concept of 'userInfo' that's used on iOS). https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java#L58

rozele added a commit to rozele/react-native-windows that referenced this issue Oct 3, 2016
Using System.Exception.Data IDictionary, users can add arbitrary data to a "userInfo" property on the error object.

Fixes microsoft#730
@rozele rozele self-assigned this Oct 3, 2016
rozele added a commit to rozele/react-native-windows that referenced this issue Oct 5, 2016
Using System.Exception.Data IDictionary, users can add arbitrary data to a "userInfo" property on the error object.

Fixes microsoft#730
rozele added a commit that referenced this issue Oct 5, 2016
Using System.Exception.Data IDictionary, users can add arbitrary data to a "userInfo" property on the error object.

Fixes #730
@rozele rozele removed the in progress label Oct 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants