Merge pull request #1520 from c9s/edwin/okx/add-response-validation-func

FEATURE: [okx] add response validation func
This commit is contained in:
c9s 2024-02-05 11:42:03 +08:00 committed by GitHub
commit 3c73c28141
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
@ -246,3 +247,14 @@ type APIResponse struct {
Message string `json:"msg"`
Data json.RawMessage `json:"data"`
}
func (a APIResponse) Validate() error {
if a.Code != "0" {
return a.Error()
}
return nil
}
func (a APIResponse) Error() error {
return fmt.Errorf("retCode: %s, retMsg: %s", a.Code, a.Message)
}