Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fixed FileNotFoundException thrown when canceled and internet is turn…
Browse files Browse the repository at this point in the history
…ed off in uwp. (#1358)
  • Loading branch information
IlGalvo committed Sep 14, 2020
1 parent 4be08ff commit 8d8a7e1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions Xamarin.Essentials/WebAuthenticator/WebAuthenticator.uwp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
Expand All @@ -17,20 +19,27 @@ static async Task<WebAuthenticatorResult> PlatformAuthenticateAsync(Uri url, Uri
if (!IsUriProtocolDeclared(callbackUrl.Scheme))
throw new InvalidOperationException($"You need to declare the windows.protocol usage of the protocol/scheme `{callbackUrl.Scheme}` in your AppxManifest.xml file");

var r = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url, callbackUrl);
try
{
var r = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, url, callbackUrl);

switch (r.ResponseStatus)
switch (r.ResponseStatus)
{
case WebAuthenticationStatus.Success:
// For GET requests this is a URI:
var resultUri = new Uri(r.ResponseData.ToString());
return new WebAuthenticatorResult(resultUri);
case WebAuthenticationStatus.UserCancel:
throw new TaskCanceledException();
case WebAuthenticationStatus.ErrorHttp:
throw new HttpRequestException("Error: " + r.ResponseErrorDetail);
default:
throw new Exception("Response: " + r.ResponseData.ToString() + "\nStatus: " + r.ResponseStatus);
}
}
catch (FileNotFoundException)
{
case WebAuthenticationStatus.Success:
// For GET requests this is a URI:
var resultUri = new Uri(r.ResponseData.ToString());
return new WebAuthenticatorResult(resultUri);
case WebAuthenticationStatus.UserCancel:
throw new TaskCanceledException();
case WebAuthenticationStatus.ErrorHttp:
throw new UnauthorizedAccessException();
default:
throw new Exception(r.ResponseData.ToString());
throw new TaskCanceledException();
}
}

Expand Down

0 comments on commit 8d8a7e1

Please sign in to comment.