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,11 +73,14 @@ 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);
|
||||||
|
|
||||||
|
if(errorResponseModel.ValidationErrors.Count > 0)
|
||||||
|
{
|
||||||
foreach(var valError in errorResponseModel.ValidationErrors)
|
foreach(var valError in errorResponseModel.ValidationErrors)
|
||||||
{
|
{
|
||||||
foreach(var errorMessage in valError.Value)
|
foreach(var errorMessage in valError.Value)
|
||||||
|
@ -86,6 +89,11 @@ namespace Bit.App.Repositories
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
errors.Add(new ApiError { Message = errorResponseModel.Message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue