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,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;