Skip to content

Commit 9525074

Browse files
zhongwuzwfacebook-github-bot
authored andcommitted
Fixes Reject error kind in Fabric (#41955)
Summary: Fixes #41950 . bypass-github-export-checks ## Changelog: [IOS] [FIXED] - Fixes Reject error kind in Fabric Pull Request resolved: #41955 Test Plan: reject returns `Error`. Reviewed By: javache Differential Revision: D52622682 Pulled By: cipolleschi fbshipit-source-id: 726e68d968d03505748191263b7e6b75a068c130
1 parent 7d8af3b commit 9525074

File tree

1 file changed

+16
-4
lines changed
  • packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon

1 file changed

+16
-4
lines changed

packages/react-native/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
211211
return {runtime, std::move(error)};
212212
}
213213

214+
/**
215+
* Creates JS error value with current JS runtime and error details.
216+
*/
217+
static jsi::Value convertJSErrorDetailsToJSRuntimeError(jsi::Runtime &runtime, NSDictionary *jsErrorDetails)
218+
{
219+
NSString *message = jsErrorDetails[@"message"];
220+
221+
auto jsError = createJSRuntimeError(runtime, [message UTF8String]);
222+
jsError.asObject(runtime).setProperty(runtime, "cause", convertObjCObjectToJSIValue(runtime, jsErrorDetails));
223+
224+
return jsError;
225+
}
226+
214227
}
215228

216229
jsi::Value ObjCTurboModule::createPromise(jsi::Runtime &runtime, std::string methodName, PromiseInvocationBlock invoke)
@@ -279,11 +292,10 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
279292
return;
280293
}
281294

282-
NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
283-
reject->call([jsError](jsi::Runtime &rt, jsi::Function &jsFunction) {
284-
jsFunction.call(rt, convertObjCObjectToJSIValue(rt, jsError));
295+
NSDictionary *jsErrorDetails = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
296+
reject->call([jsErrorDetails](jsi::Runtime &rt, jsi::Function &jsFunction) {
297+
jsFunction.call(rt, convertJSErrorDetailsToJSRuntimeError(rt, jsErrorDetails));
285298
});
286-
287299
resolveWasCalled = NO;
288300
resolve = std::nullopt;
289301
reject = std::nullopt;

0 commit comments

Comments
 (0)