Skip to content

Commit

Permalink
Merge pull request #1520 from c9s/edwin/okx/add-response-validation-func
Browse files Browse the repository at this point in the history
FEATURE: [okx] add response validation func
  • Loading branch information
c9s authored Feb 5, 2024
2 parents a800a59 + 3846b2a commit 3c73c28
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/exchange/okex/okexapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -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)
}

0 comments on commit 3c73c28

Please sign in to comment.