mirror of
https://github.com/celogeek/go-qbittorrent-sync.git
synced 2025-05-24 16:02:37 +02:00
threat forbidden as an error
This commit is contained in:
parent
2c197e2208
commit
600de44787
3
main.go
3
main.go
@ -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))
|
||||||
|
@ -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().
|
||||||
|
Loading…
x
Reference in New Issue
Block a user