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