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

Missing MsalClientException.NetworkNotAvailableError on iOS & Android #592

Closed
KarinBerg opened this issue Jul 16, 2018 · 9 comments
Closed

Comments

@KarinBerg
Copy link

KarinBerg commented Jul 16, 2018

For platform Xamarin.iOS and Xamarin.Android there is no check for an available network connection in class WebUI. So in this case an HttpRequestException is thrown and not the expected MsalClientException with ErrorCode "NetworkNotAvailableError".

Please add an network connection check for this platforms to be consistent over all platforms.

@bgavrilMS bgavrilMS added the bug label Jul 17, 2018
@bgavrilMS
Copy link
Member

@jmprieur
Copy link
Contributor

  • @henrik-me : I don't see any reason not to have this on iOS and Android (if this is possible to do)

@henrik-me henrik-me assigned henrik-me and bgavrilMS and unassigned henrik-me Aug 1, 2018
@henrik-me
Copy link
Contributor

Will require a bit of refactoring. I assume this is possible especially with the latest updates in the dev branch. @bgavrilMS can you pls. take a look at this?

@henrik-me
Copy link
Contributor

@bgavrilMS : still relevant? Putting this in 4.3.
@jmprieur : fix or close? (#Supportability)

@bgavrilMS bgavrilMS removed their assignment Jul 31, 2019
@bgavrilMS
Copy link
Member

bgavrilMS commented Jul 31, 2019

I had a look at this and I propose we fix it by removing the custom exception from .net (this is a breaking behavioural change though), but then again so is the proposed change. I think the impact is minimal because MSAL will almost never throw this exception - if the Internet is down then one of the discovery calls will fail before getting to the WebUI logic.

The reasons:

  • Network is down exceptions are fairly common and app developers should treat them. Even a generic "Something went wrong" message would do. Xamarin.Essentials provide a nice API for that

  • MSAL makes many calls to the network, such as discovery calls. It would be a perf hit to try to read the state of the network before each HTTP call. It would be inconsistent to throw

  • Catching HTTP exceptions and repackaging them would also be a breaking change to our

  • Detecting that the network is down is tricky - see how it's been done in Xamarin Essentials - https://github.com/xamarin/Essentials/blob/master/Xamarin.Essentials/Connectivity/Connectivity.android.cs - also note that it does not guarantee that a device has Internet, it just shows that a connection is available.

All in all, I don't think it's MSAL's responsibility to provide internet detection capabilities. App developers should not have to have special catch blocks for MSAL.

This is easier:

try
{
   // call MSAL
   // call some other logic that makes HTTP calls
}
catch HttpException
  // Handle HTTP issues

Than custom handling:

try
{
   // call MSAL
   // call some other logic that makes HTTP calls
}
catch (MsalClientException ex) when ex.ErrorCode == NetworkIsDown
{
   // handle MSAL
}
catch HttpException
{
 // handle all other Http issues
}

@jmprieur
Copy link
Contributor

This makes sense to me.
Let's provide guidance, then. Let's show this in our sample and the Mobile scenario landing page, as well as the error handling wiki/docs.ms page?

@henrik-me
Copy link
Contributor

I'm ok with this. Only reason to consider leaving is the consideration for a major version bump.

@henrik-me henrik-me added the Fixed label Aug 2, 2019
@henrik-me
Copy link
Contributor

Fix for consistency means the library will not handle network down type of errors.

@jennyf19
Copy link
Collaborator

jennyf19 commented Aug 8, 2019

Included in 4.3.0 release

@jennyf19 jennyf19 closed this as completed Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants