Skip to content

Commit

Permalink
Update review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongwuzw committed Jan 9, 2024
1 parent 005a88d commit 8dc0647
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,20 @@ id convertJSIValueToObjCObject(jsi::Runtime &runtime, const jsi::Value &value, s
}
return;
}
reject->call([message](jsi::Runtime &rt, jsi::Function &jsFunction) {
jsFunction.call(
rt, createJSRuntimeError(rt, [message ?: @"Unknown error from a native module" UTF8String]));

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);
NSString *message =
jsErrorDetails[@"message"] ? jsErrorDetails[@"message"] : @"Unknown error from a native module";
auto jsError =
rt.global().getPropertyAsFunction(rt, "Error").call(rt, [message UTF8String], jsiObjCError);
jsFunction.call(rt, jsError);
});
resolveWasCalled = NO;
resolve = std::nullopt;
Expand Down

0 comments on commit 8dc0647

Please sign in to comment.