Inheritance: Amazon.Runtime.AmazonServiceException
Example #1
0
        public AmazonCloudWatchException(string message, Exception innerException) : base(message, innerException)
        {
            this.message = message;
            AmazonCloudWatchException exception = innerException as AmazonCloudWatchException;

            if (exception != null)
            {
                this.statusCode = exception.StatusCode;
                this.errorCode  = exception.ErrorCode;
                this.errorType  = exception.ErrorType;
                this.requestId  = exception.RequestId;
                this.xml        = exception.XML;
            }
        }
        /**
         * Look for additional error strings in the response and return formatted exception
         */
        private static AmazonCloudWatchException ReportAnyErrors(string responseBody, HttpStatusCode status)
        {
            AmazonCloudWatchException ex = null;

            if (responseBody != null &&
                responseBody.StartsWith("<"))
            {
                Match errorMatcherOne = Regex.Match(
                    responseBody,
                    "<RequestId>(.*)</RequestId>.*<Error><Code>(.*)</Code><Message>(.*)</Message></Error>.*(<Error>)?",
                    RegexOptions.Multiline
                    );
                Match errorMatcherTwo = Regex.Match(
                    responseBody,
                    "<Error><Code>(.*)</Code><Message>(.*)</Message></Error>.*(<Error>)?.*<RequestID>(.*)</RequestID>",
                    RegexOptions.Multiline
                    );

                if (errorMatcherOne.Success)
                {
                    string requestId = errorMatcherOne.Groups[1].Value;
                    string code      = errorMatcherOne.Groups[2].Value;
                    string message   = errorMatcherOne.Groups[3].Value;

                    ex = new AmazonCloudWatchException(message, status, code, "Unknown", requestId, responseBody);
                }
                else if (errorMatcherTwo.Success)
                {
                    string code      = errorMatcherTwo.Groups[1].Value;
                    string message   = errorMatcherTwo.Groups[2].Value;
                    string requestId = errorMatcherTwo.Groups[4].Value;

                    ex = new AmazonCloudWatchException(message, status, code, "Unknown", requestId, responseBody);
                }
                else
                {
                    ex = new AmazonCloudWatchException("Internal Error", status);
                }
            }
            else
            {
                ex = new AmazonCloudWatchException("Internal Error", status);
            }
            return(ex);
        }