diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java index 92ce60699ce807..84b802b28affae 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java @@ -19,5 +19,8 @@ public interface Promise { void resolve(Object value); void reject(Throwable reason); + @Deprecated void reject(String reason); + void reject(String code, Throwable extra); + void reject(String code, String reason, Throwable extra); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java index d6e25b694fb9bf..efbc4537592d52 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java @@ -15,6 +15,9 @@ import javax.annotation.Nullable; public class PromiseImpl implements Promise { + + private static final String DEFAULT_ERROR = "EUNSPECIFIED"; + private @Nullable Callback mResolve; private @Nullable Callback mReject; @@ -32,18 +35,33 @@ public void resolve(Object value) { @Override public void reject(Throwable reason) { - reject(reason.getMessage()); + reject(DEFAULT_ERROR, reason.getMessage(), reason); } @Override + @Deprecated public void reject(String reason) { + reject(DEFAULT_ERROR, reason, null); + } + + @Override + public void reject(String code, Throwable extra) { + reject(code, extra.getMessage(), extra); + } + + @Override + public void reject(String code, String reason, Throwable extra) { if (mReject != null) { + if (code == null) { + code = DEFAULT_ERROR; + } // The JavaScript side expects a map with at least the error message. // It is possible to expose all kind of information. It will be available on the JS // error instance. - // TODO(8850038): add more useful information, e.g. the native stack trace. WritableNativeMap errorInfo = new WritableNativeMap(); + errorInfo.putString("code", code); errorInfo.putString("message", reason); + // TODO(8850038): add the stack trace info in, need to figure out way to serialize that mReject.invoke(errorInfo); } }