diff --git a/internal/pkg/tribally/tribally.go b/internal/pkg/tribally/tribally.go index b86439b..3d3befb 100644 --- a/internal/pkg/tribally/tribally.go +++ b/internal/pkg/tribally/tribally.go @@ -2,7 +2,9 @@ package tribally import ( "encoding/json" + "errors" "fmt" + "github.com/zeromicro/go-zero/core/logx" "io" "net/http" "strings" @@ -26,25 +28,28 @@ func BindTribally(apiKey, userId string) (string, error) { } defer res.Body.Close() + if res.StatusCode != http.StatusOK { + return "", errors.New(res.Status) + } + body, err := io.ReadAll(res.Body) if err != nil { return "", err } result := struct { - Error string `json:"error"` - Code string `json:"code"` - Data struct { - AuthURL string `json:"authUrl"` - } `json:"data"` + Error string `json:"error"` + Code string `json:"code"` + AuthURL string `json:"authUrl"` }{} err = json.Unmarshal(body, &result) if err != nil { return "", err } + logx.Errorw("============", logx.Field("body", string(body))) if result.Error != "" { return "", fmt.Errorf("error: %s, code: %s", result.Error, result.Code) } - return result.Data.AuthURL, nil + return result.AuthURL, nil } func VerifyTribally(token string) error {