1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-16 08:13:20 +00:00

catch WebExceptions during API calls

This commit is contained in:
Kyle Spearrin
2016-08-06 19:33:04 -04:00
parent 98ceaba5f5
commit fe1545fbdf
7 changed files with 218 additions and 92 deletions

View File

@@ -4,6 +4,7 @@ using System.Threading.Tasks;
using Bit.App.Abstractions;
using Bit.App.Models.Api;
using Plugin.Connectivity.Abstractions;
using System.Net;
namespace Bit.App.Repositories
{
@@ -30,13 +31,20 @@ namespace Bit.App.Repositories
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/register")),
};
var response = await client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
try
{
return await HandleErrorAsync(response);
}
var response = await client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
}
return ApiResult.Success(response.StatusCode);
return ApiResult.Success(response.StatusCode);
}
catch(WebException)
{
return HandledWebException();
}
}
}
@@ -55,13 +63,20 @@ namespace Bit.App.Repositories
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/password-hint")),
};
var response = await client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
try
{
return await HandleErrorAsync(response);
}
var response = await client.SendAsync(requestMessage);
if(!response.IsSuccessStatusCode)
{
return await HandleErrorAsync(response);
}
return ApiResult.Success(response.StatusCode);
return ApiResult.Success(response.StatusCode);
}
catch(WebException)
{
return HandledWebException();
}
}
}
}