Exemple #1
0
        private Exception ParseErrors(WebException exception, string error)
        {
            JObject obj;

            try
            {
                obj = (JObject)JToken.Parse(error);
            }
            catch
            {
                // If we cannot parse the error response, we're just rethrowing the
                // original exception.

                return(exception);
            }

            // First check whether it's a simple response.

            if (obj["message"] != null)
            {
                var message = obj["message"];

                if (message.Type == JTokenType.String)
                {
                    return(new ApiException((string)message, (string)obj["call_stack"], exception));
                }

                if (message.Type == JTokenType.Array && message.Count() > 0)
                {
                    return(new ApiException((string)((JArray)message)[0], (string)obj["call_stack"], exception));
                }

                // If we can't make sense of the response, throw the original exception.

                return(exception);
            }

            // Next, see whether we got an error collection.

            if (obj["errors"] != null && obj["errors"].Type == JTokenType.Array)
            {
                return(new ApiException("Validation failed", exception, ApiRowErrorsCollection.FromJson((JArray)obj["errors"])));
            }

            // If all else fails, rethrow the original exception.

            return(exception);
        }
Exemple #2
0
        internal static ApiRowErrorsCollection FromJson(JArray errors)
        {
            if (errors == null)
            {
                throw new ArgumentNullException(nameof(errors));
            }

            var result = new ApiRowErrorsCollection();

            foreach (var row in errors)
            {
                if (row.Type == JTokenType.Object)
                {
                    result.Add(ApiRowErrors.FromJson((JObject)row));
                }
            }

            return(result);
        }
Exemple #3
0
 public ApiException(string message, Exception innerException, ApiRowErrorsCollection errors)
     : base(message, innerException)
 {
     _errors = errors;
 }
Exemple #4
0
 public ApiException(ApiRowErrorsCollection errors)
 {
     _errors = errors;
 }