From a22b45eb2fa414abc92fe9d7af3ba5d0b2a3b95c Mon Sep 17 00:00:00 2001 From: jager Date: Fri, 25 Apr 2025 15:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E8=BF=94=E5=9B=9E=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pkg/tribally/tribally.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 {