diff --git a/main.go b/main.go index b850368..4213ddc 100644 --- a/main.go +++ b/main.go @@ -64,6 +64,9 @@ func main() { torrents, err := qcli.List() if err != nil { log.Printf("[QBit] List Error: %v", err) + if err.Error() == "forbidden" { + log.Fatal("Need to authenticate again. Exiting ...") + } } if len(torrents) > 0 { log.Printf("[QBit] Found %d torrents to sync", len(torrents)) diff --git a/qbittorent.go b/qbittorent.go index 33b6c67..d8397b7 100644 --- a/qbittorent.go +++ b/qbittorent.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "net/http" "strings" "github.com/go-resty/resty/v2" @@ -34,6 +35,12 @@ type Torrent struct { func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) { r := resty.New().SetBaseURL(fmt.Sprintf("%s/api/v2", options.Uri)) + r.OnAfterResponse(func(c *resty.Client, r *resty.Response) error { + if r.StatusCode() == http.StatusForbidden { + return errors.New("forbidden") + } + return nil + }) result, err := r. R().