mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat(download-clients): improve errors for starr apps (#250)
* feat(actions): improve errors for starr apps * fix: tests expected error * feat: radarr improve logging * feat: sonarr improve logging and errors * feat: lidarr improve logging and errors
This commit is contained in:
parent
e5a95415a1
commit
3d018404a9
8 changed files with 279 additions and 107 deletions
|
@ -2,7 +2,7 @@ package radarr
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -66,22 +66,18 @@ type SystemStatusResponse struct {
|
|||
}
|
||||
|
||||
func (c *client) Test() (*SystemStatusResponse, error) {
|
||||
res, err := c.get("system/status")
|
||||
status, res, err := c.get("system/status")
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client get error")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client error reading body")
|
||||
return nil, err
|
||||
if status == http.StatusUnauthorized {
|
||||
return nil, errors.New("unauthorized: bad credentials")
|
||||
}
|
||||
|
||||
response := SystemStatusResponse{}
|
||||
err = json.Unmarshal(body, &response)
|
||||
err = json.Unmarshal(res, &response)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client error json unmarshal")
|
||||
return nil, err
|
||||
|
@ -93,32 +89,20 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
|||
}
|
||||
|
||||
func (c *client) Push(release Release) ([]string, error) {
|
||||
res, err := c.post("release/push", release)
|
||||
status, res, err := c.postBody("release/push", release)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client post error")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client error reading body")
|
||||
log.Error().Stack().Err(err).Msgf("radarr client post error. status: %d", status)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pushResponse := make([]PushResponse, 0)
|
||||
err = json.Unmarshal(body, &pushResponse)
|
||||
err = json.Unmarshal(res, &pushResponse)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("radarr client error json unmarshal")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Trace().Msgf("radarr release/push response body: %+v", string(body))
|
||||
log.Trace().Msgf("radarr release/push response status: %v body: %+v", status, string(res))
|
||||
|
||||
// log and return if rejected
|
||||
if pushResponse[0].Rejected {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue