From a68c731aca86a9dfdfda678776ce4f23e463fcf5 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Thu, 3 Dec 2015 03:55:14 -0800 Subject: [PATCH] Android: Accept Throwables in Promise.reject() Summary: public Fixes #4309 This adds the possibility to reject `Promise` instances with `Throwable`s in java, instead of strings. For now, it only reads the message, but we can add more features on top of this, e.g. forwarding the error stack. Reviewed By: andreicoman11 Differential Revision: D2708192 fb-gh-sync-id: ca5ff584eca29370a9f9b780fa9825b17863a7e9 --- .../src/main/java/com/facebook/react/bridge/Promise.java | 1 + .../src/main/java/com/facebook/react/bridge/PromiseImpl.java | 5 +++++ 2 files changed, 6 insertions(+) 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 c19907af8..92ce60699 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/Promise.java @@ -18,5 +18,6 @@ package com.facebook.react.bridge; */ public interface Promise { void resolve(Object value); + void reject(Throwable reason); void reject(String reason); } 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 688b08102..d6e25b694 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/PromiseImpl.java @@ -30,6 +30,11 @@ public class PromiseImpl implements Promise { } } + @Override + public void reject(Throwable reason) { + reject(reason.getMessage()); + } + @Override public void reject(String reason) { if (mReject != null) {