Переглянути джерело

Bug fix: Replenish user interface

归邪 8 роки тому
батько
коміт
592c91f91a
5 змінених файлів з 52 додано та 3 видалено
  1. 3 0
      ChangeLog.txt
  2. 35 0
      sdk/config.go
  3. 4 2
      sdk/errors/client_error.go
  4. 3 1
      sdk/errors/server_error.go
  5. 7 0
      sdk/responses/response.go

+ 3 - 0
ChangeLog.txt

@@ -1,3 +1,6 @@
+2018-01-11 Version: 0.7.7
+1, Bug fix: Replenish user interface
+
 2018-01-11 Version: 0.7.6
 1, replace photo tag 2000 upgrade to 5000
 2, add TrashQuota

+ 35 - 0
sdk/config.go

@@ -43,6 +43,41 @@ func (c *Config) WithTimeout(timeout time.Duration) *Config {
 	return c
 }
 
+func (c *Config) WithAutoRetry(isAutoRetry bool) *Config {
+	c.AutoRetry = isAutoRetry
+	return c
+}
+
+func (c *Config) WithMaxRetryTime(maxRetryTime int) *Config {
+	c.MaxRetryTime = maxRetryTime
+	return c
+}
+
+func (c *Config) WithUserAgent(userAgent string) *Config {
+	c.UserAgent = userAgent
+	return c
+}
+
+func (c *Config) WithHttpTransport(httpTransport *http.Transport) *Config {
+	c.HttpTransport = httpTransport
+	return c
+}
+
+func (c *Config) WithEnableAsync(isEnableAsync bool) *Config {
+	c.EnableAsync = isEnableAsync
+	return c
+}
+
+func (c *Config) WithMaxTaskQueueSize(maxTaskQueueSize int) *Config {
+	c.MaxTaskQueueSize = maxTaskQueueSize
+	return c
+}
+
+func (c *Config) WithGoRoutinePoolSize(goRoutinePoolSize int) *Config {
+	c.GoRoutinePoolSize = goRoutinePoolSize
+	return c
+}
+
 func (c *Config) WithDebug(isDebug bool) *Config {
 	c.Debug = isDebug
 	return c

+ 4 - 2
sdk/errors/client_error.go

@@ -14,6 +14,8 @@
 
 package errors
 
+import "fmt"
+
 const (
 	DefaultClientErrorStatus = 400
 	DefaultClientErrorCode   = "SDK.ClientError"
@@ -54,9 +56,9 @@ func NewClientError(errorCode, message string, originErr error) Error {
 func (err *ClientError) Error() string {
 	if err.originError != nil {
 		return err.originError.Error()
-	} else {
-		return ""
 	}
+
+	return fmt.Sprintf("[%s] %s", err.errorCode, err.message)
 }
 
 func (err *ClientError) OriginError() error {

+ 3 - 1
sdk/errors/server_error.go

@@ -14,6 +14,8 @@
 
 package errors
 
+import "fmt"
+
 type ServerError struct {
 	httpStatus int
 	errorCode  string
@@ -41,7 +43,7 @@ func (err *ServerError) Message() string {
 }
 
 func (err *ServerError) Error() string {
-	return "SDK.ServerError"
+	return fmt.Sprintf("SDK.ServerError %s %s", err.errorCode, err.message)
 }
 
 func (err *ServerError) OriginError() error {

+ 7 - 0
sdk/responses/response.go

@@ -16,7 +16,9 @@ package responses
 
 import (
 	"bytes"
+	"encoding/json"
 	"encoding/xml"
+	"github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
 	"io/ioutil"
 	"net/http"
 	"strconv"
@@ -24,6 +26,7 @@ import (
 )
 
 type AcsResponse interface {
+	IsSuccess() bool
 	GetHttpStatus() int
 	GetHttpHeaders() map[string][]string
 	GetHttpContentString() string
@@ -37,6 +40,10 @@ func Unmarshal(response AcsResponse, httpResponse *http.Response, format string)
 	if err != nil {
 		return
 	}
+	if !response.IsSuccess() {
+		err = errors.NewServerError(response.GetHttpStatus(), response.GetOriginHttpResponse().Status, response.GetHttpContentString())
+		return
+	}
 	if strings.ToUpper(format) == "JSON" {
 		initJsonParserOnce()
 		err = jsonParser.Unmarshal(response.GetHttpContentBytes(), response)