Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
improve error
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao authored and AxiosLeo committed Sep 16, 2020
1 parent 5ff892f commit cffbca8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ChangLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2020-09-16 Version: v1.1.7
- Improve Error.

2020-09-11 Version: v1.1.6
- Update go mod.

Expand Down
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ func (client *Client) DoRequest(action *string, protocol *string, method *string
res := util.AssertAsMap(obj)
if tea.BoolValue(util.Is4xx(response_.StatusCode)) || tea.BoolValue(util.Is5xx(response_.StatusCode)) {
_err = tea.NewSDKError(map[string]interface{}{
"code": tea.ToString(DefaultAny(res["Code"], res["code"])) + "Error",
"message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(res["Message"], res["message"])) + " requestid: " + tea.ToString(DefaultAny(res["RequestId"], res["requestId"])),
"code": tea.ToString(DefaultAny(res["Code"], res["code"])),
"message": "code: " + tea.ToString(tea.IntValue(response_.StatusCode)) + ", " + tea.ToString(DefaultAny(res["Message"], res["message"])) + " request id: " + tea.ToString(DefaultAny(res["RequestId"], res["requestId"])),
"data": res,
})
return _result, _err
Expand Down
4 changes: 2 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ func Test_DoRequest(t *testing.T) {
resp, err := client.DoRequest(tea.String("testApi"), tea.String("HTTP"), tea.String("GET"),
tea.String("2019-12-12"), tea.String("AK"), nil, nil, runtime)
utils.AssertNotNil(t, err)
utils.AssertEqual(t, err.Error(), "SDKError:\n Code: 杭州Error\n Message: code: 400, <nil> requestid: <nil>\n Data: {\"Code\":\"杭州\"}\n")
utils.AssertEqual(t, err.Error(), "SDKError:\n Code: 杭州\n Message: code: 400, <nil> request id: <nil>\n Data: {\"Code\":\"杭州\"}\n")
utils.AssertNil(t, resp)

runtime.SetMaxAttempts(3).SetAutoretry(true).SetBackoffPeriod(1).SetBackoffPolicy("ok")
resp, err = client.DoRequest(tea.String("testApi"), tea.String("HTTP"), tea.String("GET"),
tea.String("2019-12-12"), tea.String("AK"), nil, map[string]interface{}{"test": "ok"}, runtime)
utils.AssertNotNil(t, err)
utils.AssertEqual(t, err.Error(), "SDKError:\n Code: 杭州Error\n Message: code: 400, <nil> requestid: <nil>\n Data: {\"Code\":\"杭州\"}\n")
utils.AssertEqual(t, err.Error(), "SDKError:\n Code: 杭州\n Message: code: 400, <nil> request id: <nil>\n Data: {\"Code\":\"杭州\"}\n")
utils.AssertNil(t, resp)

ts = mockServer(200, `{"Code": "杭州"}`)
Expand Down

0 comments on commit cffbca8

Please sign in to comment.