mirror of
https://github.com/idanoo/autobrr
synced 2025-07-24 01:09:13 +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 sonarr
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -67,60 +67,44 @@ 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("sonarr 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("sonarr client error reading body")
|
||||
return nil, err
|
||||
if status == http.StatusUnauthorized {
|
||||
return nil, errors.New("unauthorized: bad credentials")
|
||||
}
|
||||
|
||||
log.Trace().Msgf("sonarr system/status response: %v", string(res))
|
||||
|
||||
response := SystemStatusResponse{}
|
||||
err = json.Unmarshal(body, &response)
|
||||
err = json.Unmarshal(res, &response)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("sonarr client error json unmarshal")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Trace().Msgf("sonarr system/status response: %+v", response)
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
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("sonarr 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("sonarr client error reading body")
|
||||
return nil, err
|
||||
}
|
||||
log.Trace().Msgf("sonarr release/push response status: (%v) body: %v", status, string(res))
|
||||
|
||||
pushResponse := make([]PushResponse, 0)
|
||||
err = json.Unmarshal(body, &pushResponse)
|
||||
err = json.Unmarshal(res, &pushResponse)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("sonarr client error json unmarshal")
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Trace().Msgf("sonarr release/push response body: %+v", string(body))
|
||||
|
||||
// log and return if rejected
|
||||
if pushResponse[0].Rejected {
|
||||
rejections := strings.Join(pushResponse[0].Rejections, ", ")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue