mirror of
https://github.com/bitwarden/mobile
synced 2026-01-04 09:33:16 +00:00
catch WebExceptions during API calls
This commit is contained in:
@@ -6,6 +6,7 @@ using Bit.App.Abstractions;
|
||||
using Bit.App.Models.Api;
|
||||
using Newtonsoft.Json;
|
||||
using Plugin.Connectivity.Abstractions;
|
||||
using System.Net;
|
||||
|
||||
namespace Bit.App.Repositories
|
||||
{
|
||||
@@ -32,15 +33,22 @@ namespace Bit.App.Repositories
|
||||
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/", id)),
|
||||
};
|
||||
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
try
|
||||
{
|
||||
return await HandleErrorAsync<CipherResponse>(response);
|
||||
}
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<CipherResponse>(response);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<CipherResponse>(responseContent);
|
||||
return ApiResult<CipherResponse>.Success(responseObj, response.StatusCode);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<CipherResponse>(responseContent);
|
||||
return ApiResult<CipherResponse>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch(WebException)
|
||||
{
|
||||
return HandledWebException<CipherResponse>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,15 +67,22 @@ namespace Bit.App.Repositories
|
||||
RequestUri = new Uri(client.BaseAddress, ApiRoute),
|
||||
};
|
||||
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
try
|
||||
{
|
||||
return await HandleErrorAsync<ListResponse<CipherResponse>>(response);
|
||||
}
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<ListResponse<CipherResponse>>(response);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<ListResponse<CipherResponse>>(responseContent);
|
||||
return ApiResult<ListResponse<CipherResponse>>.Success(responseObj, response.StatusCode);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<ListResponse<CipherResponse>>(responseContent);
|
||||
return ApiResult<ListResponse<CipherResponse>>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch(WebException)
|
||||
{
|
||||
return HandledWebException<ListResponse<CipherResponse>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,15 +101,22 @@ namespace Bit.App.Repositories
|
||||
RequestUri = new Uri(client.BaseAddress, string.Concat(ApiRoute, "/history", "?since=", since)),
|
||||
};
|
||||
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
try
|
||||
{
|
||||
return await HandleErrorAsync<CipherHistoryResponse>(response);
|
||||
}
|
||||
var response = await client.SendAsync(requestMessage);
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
return await HandleErrorAsync<CipherHistoryResponse>(response);
|
||||
}
|
||||
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<CipherHistoryResponse>(responseContent);
|
||||
return ApiResult<CipherHistoryResponse>.Success(responseObj, response.StatusCode);
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
var responseObj = JsonConvert.DeserializeObject<CipherHistoryResponse>(responseContent);
|
||||
return ApiResult<CipherHistoryResponse>.Success(responseObj, response.StatusCode);
|
||||
}
|
||||
catch(WebException)
|
||||
{
|
||||
return HandledWebException<CipherHistoryResponse>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user