null checks when error handling

This commit is contained in:
Kyle Spearrin 2017-02-07 21:56:28 -05:00
parent 8a525aee8a
commit e71adbd26d

View file

@ -191,17 +191,20 @@ namespace Bit.App.Repositories
var statusCode = (int)response.StatusCode; var statusCode = (int)response.StatusCode;
if(statusCode >= 400 && statusCode <= 500) if(statusCode >= 400 && statusCode <= 500)
{ {
var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
ErrorResponse errorResponseModel = null; ErrorResponse errorResponseModel = null;
var errorResponse = JObject.Parse(responseContent);
if(errorResponse["ErrorModel"] != null && errorResponse["ErrorModel"]["Message"] != null) var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if(!string.IsNullOrWhiteSpace(responseContent))
{ {
errorResponseModel = errorResponse["ErrorModel"].ToObject<ErrorResponse>(); var errorResponse = JObject.Parse(responseContent);
} if(errorResponse["ErrorModel"] != null && errorResponse["ErrorModel"]["Message"] != null)
else if(errorResponse["Message"] != null) {
{ errorResponseModel = errorResponse["ErrorModel"].ToObject<ErrorResponse>();
errorResponseModel = errorResponse.ToObject<ErrorResponse>(); }
else if(errorResponse["Message"] != null)
{
errorResponseModel = errorResponse.ToObject<ErrorResponse>();
}
} }
if(errorResponseModel != null) if(errorResponseModel != null)