threat forbidden as an error

This commit is contained in:
Celogeek 2023-11-29 09:34:00 +01:00
parent 2c197e2208
commit 600de44787
Signed by: celogeek
SSH Key Fingerprint: SHA256:DEDfxIK2nUWXbslbRkww3zsauDjhWHlTXar+ak4lDJ4
2 changed files with 10 additions and 0 deletions

View File

@ -64,6 +64,9 @@ func main() {
torrents, err := qcli.List() torrents, err := qcli.List()
if err != nil { if err != nil {
log.Printf("[QBit] List Error: %v", err) log.Printf("[QBit] List Error: %v", err)
if err.Error() == "forbidden" {
log.Fatal("Need to authenticate again. Exiting ...")
}
} }
if len(torrents) > 0 { if len(torrents) > 0 {
log.Printf("[QBit] Found %d torrents to sync", len(torrents)) log.Printf("[QBit] Found %d torrents to sync", len(torrents))

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"net/http"
"strings" "strings"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
@ -34,6 +35,12 @@ type Torrent struct {
func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) { func NewQBittorrentCli(options *QBitTorrentOptions) (*QBittorrentCli, error) {
r := resty.New().SetBaseURL(fmt.Sprintf("%s/api/v2", options.Uri)) 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. result, err := r.
R(). R().