Skip to content

Commit

Permalink
Fixes Reject error kind in Fabric (facebook#41955)
Browse files Browse the repository at this point in the history
Summary:
Fixes facebook#41950 .

bypass-github-export-checks

## Changelog:

[IOS] [FIXED] - Fixes Reject error kind in Fabric

Pull Request resolved: facebook#41955

Test Plan: reject returns `Error`.

Reviewed By: javache

Differential Revision: D52622682

Pulled By: cipolleschi

fbshipit-source-id: 726e68d968d03505748191263b7e6b75a068c130
  • Loading branch information
zhongwuzw authored and gokul1099 committed Jan 17, 2024
1 parent e5287b6 commit 8ecb3a6
Showing 1 changed file with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,19 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
return {runtime, std::move(error)};
}

/**
* Creates JS error value with current JS runtime and error details.
*/
static jsi::Value convertJSErrorDetailsToJSRuntimeError(jsi::Runtime &runtime, NSDictionary *jsErrorDetails)
{
NSString *message = jsErrorDetails[@"message"];

auto jsError = createJSRuntimeError(runtime, [message UTF8String]);
jsError.asObject(runtime).setProperty(runtime, "cause", convertObjCObjectToJSIValue(runtime, jsErrorDetails));

return jsError;
}

}

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

NSDictionary *jsError = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
reject->call([jsError](jsi::Runtime &rt, jsi::Function &jsFunction) {
jsFunction.call(rt, convertObjCObjectToJSIValue(rt, jsError));
NSDictionary *jsErrorDetails = RCTJSErrorFromCodeMessageAndNSError(code, message, error);
reject->call([jsErrorDetails](jsi::Runtime &rt, jsi::Function &jsFunction) {
jsFunction.call(rt, convertJSErrorDetailsToJSRuntimeError(rt, jsErrorDetails));
});

resolveWasCalled = NO;
resolve = std::nullopt;
reject = std::nullopt;
Expand Down

0 comments on commit 8ecb3a6

Please sign in to comment.