From d31756bf0195b60e8ebce56440153552d5fb97bc Mon Sep 17 00:00:00 2001 From: BaihaoTian Date: Tue, 6 Sep 2016 06:02:24 -0700 Subject: [PATCH] improve (RCTJSErrorFromCodeMessageAndNSError) Summary: First of all,please forgive my poor english. LOL When I use Promises as callBack, I followed the guide to make a (RCTPromiseRejectBlock),in this RCTPromiseRejectBlock, from the guide I should add a (NSString)code a (NSString)message and an (NSError) to a RCTPromiseRejectBlock. As what did guide said I just make a NSError with ``` NSError *error=[NSError errorWithDomain:@"native stroage error" code:402 userInfo:@{@"data":key}]; ``` As you can see, I want to transfer some data in this callback.But I just found the (userInfo) of NSError didn't composed to a RCTPromiseRejectBlock. So I check out the source code of RCTUtil ,I found this ``` // TODO: Can we just replace RCTMakeError with this function instead? NSDictionary *RCTJSErrorFromCodeMessageAndNSError(NSString *code, NSString *message, NSError *__nullable error) { NSString *errorMessage; Closes https://github.com/facebook/react-native/pull/9519 Differential Revision: D3821334 Pulled By: javache fbshipit-source-id: 0fa40dd93932af70123b8f8a20a5c7dc5afdd6ac --- React/Base/RCTUtils.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index b16503a8fe1..2241a65d8bd 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -424,6 +424,8 @@ NSDictionary *RCTJSErrorFromCodeMessageAndNSError(NSString *code errorInfo[@"domain"] = RCTErrorDomain; } errorInfo[@"code"] = code ?: RCTErrorUnspecified; + errorInfo[@"userInfo"] = RCTNullIfNil(error.userInfo); + // Allow for explicit overriding of the error message errorMessage = message ?: errorMessage;