From c0a532a0fe74079fc178bc9330f0116fbe7d8dd1 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 12 Nov 2016 18:35:52 -0500 Subject: [PATCH] Handle all 400-500 range error response models --- src/App/Repositories/BaseApiRepository.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/App/Repositories/BaseApiRepository.cs b/src/App/Repositories/BaseApiRepository.cs index dfc57003b..717094b38 100644 --- a/src/App/Repositories/BaseApiRepository.cs +++ b/src/App/Repositories/BaseApiRepository.cs @@ -73,18 +73,26 @@ namespace Bit.App.Repositories private async Task> ParseErrorsAsync(HttpResponseMessage response) { var errors = new List(); - 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(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;