From 8b10ee0028933bce076108366b2a77692316aa9d Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 24 Dec 2016 11:47:29 -0500 Subject: [PATCH] better error handling in base repo --- src/App/Repositories/BaseApiRepository.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/App/Repositories/BaseApiRepository.cs b/src/App/Repositories/BaseApiRepository.cs index c7e63ee06..429b1dfea 100644 --- a/src/App/Repositories/BaseApiRepository.cs +++ b/src/App/Repositories/BaseApiRepository.cs @@ -52,7 +52,7 @@ namespace Bit.App.Repositories var errors = await ParseErrorsAsync(response).ConfigureAwait(false); return ApiResult.Failed(response.StatusCode, errors.ToArray()); } - catch(JsonReaderException) + catch { } return ApiResult.Failed(response.StatusCode, @@ -66,7 +66,7 @@ namespace Bit.App.Repositories var errors = await ParseErrorsAsync(response).ConfigureAwait(false); return ApiResult.Failed(response.StatusCode, errors.ToArray()); } - catch(JsonReaderException) + catch { } return ApiResult.Failed(response.StatusCode, @@ -82,19 +82,26 @@ namespace Bit.App.Repositories var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var errorResponseModel = JsonConvert.DeserializeObject(responseContent); - if(errorResponseModel.ValidationErrors.Count > 0) + if(errorResponseModel != null) { - foreach(var valError in errorResponseModel.ValidationErrors) + if((errorResponseModel.ValidationErrors?.Count ?? 0) > 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 }); + } } else { - errors.Add(new ApiError { Message = errorResponseModel.Message }); + errors.Add(new ApiError { Message = "An unknown error has occured." }); } }