Skip to content

Commit

Permalink
support xml response for pop
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 authored and peze committed Apr 11, 2022
1 parent ac94f05 commit c8b881c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
spi "github.com/alibabacloud-go/alibabacloud-gateway-spi/client"
openapiutil "github.com/alibabacloud-go/openapi-util/service"
util "github.com/alibabacloud-go/tea-utils/service"
xml "github.com/alibabacloud-go/tea-xml/service"
"github.com/alibabacloud-go/tea/tea"
credential "github.com/aliyun/credentials-go/credentials"
)
Expand Down Expand Up @@ -1183,12 +1184,24 @@ func (client *Client) DoRequest(params *Params, request *OpenApiRequest, runtime
return _result, _err
}
if tea.BoolValue(util.Is4xx(response_.StatusCode)) || tea.BoolValue(util.Is5xx(response_.StatusCode)) {
_res, _err := util.ReadAsJSON(response_.Body)
if _err != nil {
return _result, _err
err := map[string]interface{}{}
if !tea.BoolValue(util.IsUnset(response_.Headers["content-type"])) && tea.BoolValue(util.EqualString(response_.Headers["content-type"], tea.String("text/xml;charset=utf-8"))) {
_str, _err := util.ReadAsString(response_.Body)
if _err != nil {
return _result, _err
}

respMap := xml.ParseXml(_str, nil)
err = util.AssertAsMap(respMap["Error"])
} else {
_res, _err := util.ReadAsJSON(response_.Body)
if _err != nil {
return _result, _err
}

err = util.AssertAsMap(_res)
}

err := util.AssertAsMap(_res)
_err = tea.NewSDKError(map[string]interface{}{
"code": tea.ToString(DefaultAny(err["Code"], err["code"])),
"message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(err["Message"], err["message"])) + " request id: " + tea.ToString(DefaultAny(err["RequestId"], err["requestId"])),
Expand Down

0 comments on commit c8b881c

Please sign in to comment.