private T ParseAcsResponse()

in aliyun-net-sdk-core/DefaultAcsClient.cs [255:313]


        private T ParseAcsResponse<T>(AcsRequest<T> request, HttpResponse httpResponse) where T : AcsResponse
        {
            CommonLog.LogInfo(request, httpResponse, CommonLog.ExecuteTime);
            var format = httpResponse.ContentType;

            if (httpResponse.isSuccess())
            {
                return ReadResponse(request, httpResponse, format);
            }

            try
            {
                var error = ReadError(request, httpResponse, format);
                if (null != error.ErrorCode)
                {
                    if (500 <= httpResponse.Status)
                    {
                        throw new ServerException(error.ErrorCode,
                            string.Format("{0}, the request url is {1}, the RequestId is {2}.", error.ErrorMessage,
                                httpResponse.Url ?? "empty", error.RequestId));
                    }

                    if (400 == httpResponse.Status && (error.ErrorCode.Equals("SignatureDoesNotMatch") ||
                            error.ErrorCode.Equals("IncompleteSignature")))
                    {
                        var errorMessage = error.ErrorMessage;
                        var re = new Regex(@"string to sign is:", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        var matches = re.Match(errorMessage);

                        if (matches.Success)
                        {
                            var errorStringToSign = errorMessage.Substring(matches.Index + matches.Length);

                            if (request.StringToSign.Equals(errorStringToSign))
                            {
                                throw new ClientException("SDK.InvalidAccessKeySecret",
                                    "Specified Access Key Secret is not valid.", error.RequestId);
                            }
                        }
                    }

                    throw new ClientException(error.ErrorCode, error.ErrorMessage, error.RequestId);
                }
            }
            catch (ServerException ex)
            {
                CommonLog.LogException(ex, ex.ErrorCode, ex.ErrorMessage);
                throw new ServerException(ex.ErrorCode, ex.ErrorMessage, ex.RequestId);
            }
            catch (ClientException ex)
            {
                CommonLog.LogException(ex, ex.ErrorCode, ex.ErrorMessage);
                throw new ClientException(ex.ErrorCode, ex.ErrorMessage, ex.RequestId);
            }

            var t = Activator.CreateInstance<T>();
            t.HttpResponse = httpResponse;
            return t;
        }