Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixes Reject error kind in Fabric #41955

Closed
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,20 @@ 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) {
// From JS documentation:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Error#cause an
// Error can be created with `new Error(message, option);`. the `option` param is a JS object with the
// `cause` property. Create a valid `option` object
NSDictionary<NSString *, id> *jsErrorOptions = @{@"cause" : jsErrorDetails};
auto jsiObjCError = convertObjCObjectToJSIValue(rt, jsErrorOptions);
zhongwuzw marked this conversation as resolved.
Show resolved Hide resolved
NSString *message =
jsErrorDetails[@"message"] ? jsErrorDetails[@"message"] : @"Unknown error from a native module";
zhongwuzw marked this conversation as resolved.
Show resolved Hide resolved
auto jsError =
rt.global().getPropertyAsFunction(rt, "Error").call(rt, [message UTF8String], jsiObjCError);
zhongwuzw marked this conversation as resolved.
Show resolved Hide resolved
jsFunction.call(rt, jsError);
});

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