mirror of
https://github.com/bitwarden/android.git
synced 2024-12-20 16:21:55 +03:00
Handle all 400-500 range error response models
This commit is contained in:
parent
feb484dc9f
commit
c0a532a0fe
1 changed files with 12 additions and 4 deletions
|
@ -73,18 +73,26 @@ namespace Bit.App.Repositories
|
||||||
private async Task<List<ApiError>> ParseErrorsAsync(HttpResponseMessage response)
|
private async Task<List<ApiError>> ParseErrorsAsync(HttpResponseMessage response)
|
||||||
{
|
{
|
||||||
var errors = new List<ApiError>();
|
var errors = new List<ApiError>();
|
||||||
if(response.StatusCode == System.Net.HttpStatusCode.BadRequest)
|
var statusCode = (int)response.StatusCode;
|
||||||
|
if(statusCode >= 400 && statusCode <= 500)
|
||||||
{
|
{
|
||||||
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
var errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
|
var errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
|
||||||
|
|
||||||
foreach(var valError in errorResponseModel.ValidationErrors)
|
if(errorResponseModel.ValidationErrors.Count > 0)
|
||||||
{
|
{
|
||||||
foreach(var errorMessage in valError.Value)
|
foreach(var valError in errorResponseModel.ValidationErrors)
|
||||||
{
|
{
|
||||||
errors.Add(new ApiError { Message = errorMessage });
|
foreach(var errorMessage in valError.Value)
|
||||||
|
{
|
||||||
|
errors.Add(new ApiError { Message = errorMessage });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.Add(new ApiError { Message = errorResponseModel.Message });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
|
|
Loading…
Reference in a new issue