Handle all 400-500 range error response models

This commit is contained in:
Kyle Spearrin 2016-11-12 18:35:52 -05:00
parent feb484dc9f
commit c0a532a0fe

View file

@ -73,11 +73,14 @@ namespace Bit.App.Repositories
private async Task<List<ApiError>> ParseErrorsAsync(HttpResponseMessage response)
{
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 errorResponseModel = JsonConvert.DeserializeObject<ErrorResponse>(responseContent);
if(errorResponseModel.ValidationErrors.Count > 0)
{
foreach(var valError in errorResponseModel.ValidationErrors)
{
foreach(var errorMessage in valError.Value)
@ -86,6 +89,11 @@ namespace Bit.App.Repositories
}
}
}
else
{
errors.Add(new ApiError { Message = errorResponseModel.Message });
}
}
return errors;
}