Skip to content

Commit

Permalink
fix: unescape unicode in sdk error
Browse files Browse the repository at this point in the history
  • Loading branch information
yndu13 committed Jan 22, 2024
1 parent 2b0e131 commit 0a68664
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions tea/tea.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ func NewSDKError(obj map[string]interface{}) *SDKError {
}
}
}
byt, _ := json.Marshal(data)
err.Data = String(string(byt))
byt := bytes.NewBuffer([]byte{})
jsonEncoder := json.NewEncoder(byt)
jsonEncoder.SetEscapeHTML(false)
jsonEncoder.Encode(data)
err.Data = String(string(bytes.TrimSpace(byt.Bytes())))
}

if statusCode, ok := obj["statusCode"].(int); ok {
Expand Down
3 changes: 2 additions & 1 deletion tea/tea_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func TestSDKError(t *testing.T) {
"httpCode": "404",
"requestId": "dfadfa32cgfdcasd4313",
"hostId": "github.com/alibabacloud/tea",
"recommend": "https://中文?q=a.b&product=c&requestId=123",
},
"description": "description",
"accessDeniedDetail": map[string]interface{}{
Expand All @@ -179,7 +180,7 @@ func TestSDKError(t *testing.T) {
},
})
utils.AssertNotNil(t, err)
utils.AssertEqual(t, "SDKError:\n StatusCode: 404\n Code: code\n Message: message\n Data: {\"hostId\":\"github.com/alibabacloud/tea\",\"httpCode\":\"404\",\"requestId\":\"dfadfa32cgfdcasd4313\"}\n", err.Error())
utils.AssertEqual(t, "SDKError:\n StatusCode: 404\n Code: code\n Message: message\n Data: {\"hostId\":\"github.com/alibabacloud/tea\",\"httpCode\":\"404\",\"recommend\":\"https://中文?q=a.b&product=c&requestId=123\",\"requestId\":\"dfadfa32cgfdcasd4313\"}\n", err.Error())

err.SetErrMsg("test")
utils.AssertEqual(t, "test", err.Error())
Expand Down

0 comments on commit 0a68664

Please sign in to comment.