private T ParseAcsResponse <T>(AcsRequest <T> request, HttpResponse httpResponse) where T : AcsResponse { FormatType?format = httpResponse.ContentType; if (httpResponse.isSuccess()) { return(ReadResponse <T>(request, httpResponse, format)); } else { AcsError error = ReadError(request, httpResponse, format); if (null != error.ErrorCode) { if (500 <= httpResponse.Status) { throw new ServerException(error.ErrorCode, error.ErrorMessage, error.RequestId); } else { throw new ClientException(error.ErrorCode, error.ErrorMessage, error.RequestId); } } else { T t = System.Activator.CreateInstance <T>(); t.HttpResponse = httpResponse; return(t); } } }
private T ParseAcsResponse <T>(AcsRequest <T> request, HttpResponse httpResponse) where T : AcsResponse { SerilogHelper.LogInfo(request, httpResponse, SerilogHelper.ExecuteTime, SerilogHelper.StartTime); FormatType?format = httpResponse.ContentType; if (httpResponse.isSuccess()) { return(ReadResponse <T>(request, httpResponse, format)); } else { try { AcsError error = ReadError(request, httpResponse, format); if (null != error.ErrorCode) { if (500 <= httpResponse.Status) { throw new ServerException(error.ErrorCode, error.ErrorMessage, error.RequestId); } if (400 == httpResponse.Status && (error.ErrorCode.Equals("SignatureDoesNotMatch") || error.ErrorCode.Equals("IncompleteSignature"))) { var errorMessage = error.ErrorMessage; Regex re = new Regex(@"string to sign is:", RegexOptions.Compiled | RegexOptions.IgnoreCase); Match 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) { SerilogHelper.LogException(ex, ex.ErrorCode, ex.ErrorMessage); throw new ServerException(ex.ErrorCode, ex.ErrorMessage); } catch (ClientException ex) { SerilogHelper.LogException(ex, ex.ErrorCode, ex.ErrorMessage); throw new ClientException(ex.ErrorCode, ex.ErrorMessage); } T t = Activator.CreateInstance <T>(); t.HttpResponse = httpResponse; return(t); } }