/// <summary> /// Gets the error result. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="responseMessage">The response message.</param> /// <returns></returns> private static async Task <ApiError> GetErrorResult(HttpResponseMessage responseMessage) { var responseContent = await responseMessage.Content.ReadAsStringAsync(); if (!responseMessage.IsSuccessStatusCode) { return(new ApiError { ErrorMessage = string.Format( "Response status code does not indicate success: {2} ({0}).{3}{1}{3}Request: {4}", responseMessage.ReasonPhrase, responseContent, responseMessage.StatusCode, Environment.NewLine, responseMessage.RequestMessage.RequestUri), ErrorCode = (int)responseMessage.StatusCode, }); } ApiError apiError = null; try { var errorToken = JToken.Parse(responseContent); if (errorToken != null) { apiError = errorToken.ToObject <ApiError>(new JsonSerializer()); } } catch (Exception) { apiError = null; } return(apiError != null && apiError.ErrorCode != 0 ? apiError : null); }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Exception" /> class with a specified error message. /// </summary> /// <param name="error">The error.</param> public DataServiceException(ApiError error) : base(error.ErrorMessage) { _error = error; }