private async Task <ResultModel <T> > DeSerializeResult <T>(Uri resourceUri, HttpResponseMessage result)
        {
            var body = await result.Content.ReadAsStringAsync();

            if (result.IsSuccessStatusCode)
            {
                var data = JsonConvert.DeserializeObject <T>(body);

                return(new ResultModel <T>(data));
            }

            Logger.Warning($"Code:{result.StatusCode} Method:{result.RequestMessage.Method} Uri:{resourceUri} ReasonPhrase:{result.ReasonPhrase}");

            HttpApiError httpApiError = null;

            if (!string.IsNullOrEmpty(body))
            {
                try
                {
                    httpApiError = JsonConvert.DeserializeObject <HttpApiError>(body);
                }
                catch (Exception)
                {
                    httpApiError = null;
                }
            }

            return(new ResultModel <T>(new ResultError(result.ReasonPhrase, (int)result.StatusCode, httpApiError)));
        }
 public HttpApiRequestException(
     string message,
     HttpStatusCode httpStatusCode,
     HttpApiError httpError)
     : base(message)
 {
     StatusCode = httpStatusCode;
     HttpError = httpError;
 }
        public HttpApiResponseMessage(HttpResponseMessage response, HttpApiError httpError)
            : this(response)
        {
            if (httpError == null) {

                throw new ArgumentNullException("httpError");
            }

            HttpError = httpError;
        }
        public HttpApiResponseMessage(HttpResponseMessage response, HttpApiError httpError)
            : this(response)
        {
            if (httpError == null) {

                throw new ArgumentNullException("httpError");
            }

            HttpApiError modelState = httpError[ModelStateKey] as HttpApiError;

            if (modelState != null) {

                ModelState = httpError[ModelStateKey] as Dictionary<string, string[]>;
            }

            HttpError = httpError;
        }
Example #5
0
 public ResultError(string error, int code, HttpApiError apiError = null)
 {
     Error        = error;
     Code         = code;
     HttpApiError = apiError;
 }