Example #1
0
        private WebApiClientException GetException(HttpResponseMessage response)
        {
            WebApiClientExceptionDetails details = new WebApiClientExceptionDetails();
            string result = response.Content.ReadAsStringAsync().Result;

            try
            {
                Dictionary <string, IList <string> > dictionary = (Dictionary <string, IList <string> >)null;
                JObject jobject = JObject.Parse(result);
                if ((IDictionary <string, JToken>)jobject["ModelState"] != null)
                {
                    dictionary = jobject["ModelState"].ToObject <Dictionary <string, IList <string> > >();
                }
                string str1 = (string)jobject["Message"];
                string str2 = (string)jobject["ExceptionMessage"];
                details.Message       = str2 ?? str1;
                details.ExceptionType = (string)jobject["ExceptionType"];
                details.StackTrace    = (string)jobject["StackTrace"];
                details.ModelState    = dictionary;
            }
            catch
            {
                if (!string.IsNullOrEmpty(result))
                {
                    details.Message = result;
                }
            }
            details.Reason = response.ReasonPhrase;
            return(new WebApiClientException(response.StatusCode, details));
        }
 /// <summary>Creates a new object of WebApiClientException</summary>
 /// <param name="statusCode">The error code</param>
 /// <param name="details">The object with further exception details</param>
 public WebApiClientException(HttpStatusCode statusCode, WebApiClientExceptionDetails details)
     : base("Error when trying to call the WebApi. See Details for more information")
 {
     this.StatusCode = statusCode;
     this.Details    = details;
 }