Skip to content

Commit

Permalink
Report errors in linking module (#8844)
Browse files Browse the repository at this point in the history
* Catch and report errors in linking module

* format

* Change files
  • Loading branch information
asklar authored Oct 16, 2021
1 parent 585e011 commit 907119c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Catch and report errors in linking module",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
18 changes: 14 additions & 4 deletions vnext/Microsoft.ReactNative/Modules/LinkingManagerModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,24 @@ auto LinkingManagerModule::getMethods() -> std::vector<Method> {
Method(
"openURL",
[](folly::dynamic args, Callback successCallback, Callback errorCallback) {
winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0)));
openURLAsync(uri, successCallback, errorCallback);
auto inputUrl = facebook::xplat::jsArgAsString(args, 0);
try {
winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(inputUrl));
openURLAsync(uri, successCallback, errorCallback);
} catch (winrt::hresult_error &e) {
errorCallback(
{folly::dynamic::object("code", e.code().value)("message", "Unable to open URL: " + inputUrl)});
}
}),
Method(
"canOpenURL",
[](folly::dynamic args, Callback successCallback, Callback errorCallback) {
winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0)));
canOpenURLAsync(uri, successCallback, errorCallback);
try {
winrt::Windows::Foundation::Uri uri(Utf8ToUtf16(facebook::xplat::jsArgAsString(args, 0)));
canOpenURLAsync(uri, successCallback, errorCallback);
} catch (winrt::hresult_error &e) {
successCallback({false});
}
}),
Method(
"getInitialURL",
Expand Down

0 comments on commit 907119c

Please sign in to comment.