mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
feat(download-clients): improve arr error handling (#549)
This commit is contained in:
parent
33aa21fc15
commit
301180e55b
5 changed files with 61 additions and 42 deletions
|
@ -76,10 +76,15 @@ type PushResponse struct {
|
||||||
type BadRequestResponse struct {
|
type BadRequestResponse struct {
|
||||||
PropertyName string `json:"propertyName"`
|
PropertyName string `json:"propertyName"`
|
||||||
ErrorMessage string `json:"errorMessage"`
|
ErrorMessage string `json:"errorMessage"`
|
||||||
|
ErrorCode string `json:"errorCode"`
|
||||||
AttemptedValue string `json:"attemptedValue"`
|
AttemptedValue string `json:"attemptedValue"`
|
||||||
Severity string `json:"severity"`
|
Severity string `json:"severity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r BadRequestResponse) String() string {
|
||||||
|
return fmt.Sprintf("[%v: %v] %v: %v - got value: %v", r.Severity, r.ErrorCode, r.PropertyName, r.ErrorMessage, r.AttemptedValue)
|
||||||
|
}
|
||||||
|
|
||||||
type SystemStatusResponse struct {
|
type SystemStatusResponse struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
@ -114,21 +119,21 @@ func (c *client) Push(release Release) ([]string, error) {
|
||||||
c.Log.Printf("lidarr release/push response status: %v body: %v", status, string(res))
|
c.Log.Printf("lidarr release/push response status: %v body: %v", status, string(res))
|
||||||
|
|
||||||
if status == http.StatusBadRequest {
|
if status == http.StatusBadRequest {
|
||||||
badreqResponse := make([]*BadRequestResponse, 0)
|
badRequestResponses := make([]*BadRequestResponse, 0)
|
||||||
err = json.Unmarshal(res, &badreqResponse)
|
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
if badreqResponse[0] != nil && badreqResponse[0].PropertyName == "Title" && badreqResponse[0].ErrorMessage == "Unable to parse" {
|
rejections := []string{}
|
||||||
rejections := []string{fmt.Sprintf("unable to parse: %v", badreqResponse[0].AttemptedValue)}
|
for _, response := range badRequestResponses {
|
||||||
return rejections, err
|
rejections = append(rejections, response.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rejections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pushResponse := PushResponse{}
|
pushResponse := PushResponse{}
|
||||||
err = json.Unmarshal(res, &pushResponse)
|
if err = json.Unmarshal(res, &pushResponse); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "lidarr client error json unmarshal")
|
return nil, errors.Wrap(err, "lidarr client error json unmarshal")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,10 +77,15 @@ type SystemStatusResponse struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type BadRequestResponse struct {
|
type BadRequestResponse struct {
|
||||||
PropertyName string `json:"propertyName"`
|
|
||||||
ErrorMessage string `json:"errorMessage"`
|
|
||||||
AttemptedValue string `json:"attemptedValue"`
|
|
||||||
Severity string `json:"severity"`
|
Severity string `json:"severity"`
|
||||||
|
ErrorCode string `json:"errorCode"`
|
||||||
|
ErrorMessage string `json:"errorMessage"`
|
||||||
|
PropertyName string `json:"propertyName"`
|
||||||
|
AttemptedValue string `json:"attemptedValue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *BadRequestResponse) String() string {
|
||||||
|
return fmt.Sprintf("[%v: %v] %v: %v - got value: %v", r.Severity, r.ErrorCode, r.PropertyName, r.ErrorMessage, r.AttemptedValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Test() (*SystemStatusResponse, error) {
|
func (c *client) Test() (*SystemStatusResponse, error) {
|
||||||
|
@ -94,8 +99,7 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
response := SystemStatusResponse{}
|
response := SystemStatusResponse{}
|
||||||
err = json.Unmarshal(res, &response)
|
if err = json.Unmarshal(res, &response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,21 +117,21 @@ func (c *client) Push(release Release) ([]string, error) {
|
||||||
c.Log.Printf("radarr release/push status: (%v) response: %v\n", status, string(res))
|
c.Log.Printf("radarr release/push status: (%v) response: %v\n", status, string(res))
|
||||||
|
|
||||||
if status == http.StatusBadRequest {
|
if status == http.StatusBadRequest {
|
||||||
badreqResponse := make([]*BadRequestResponse, 0)
|
badRequestResponses := make([]*BadRequestResponse, 0)
|
||||||
err = json.Unmarshal(res, &badreqResponse)
|
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
if badreqResponse[0] != nil && badreqResponse[0].PropertyName == "Title" && badreqResponse[0].ErrorMessage == "Unable to parse" {
|
rejections := []string{}
|
||||||
rejections := []string{fmt.Sprintf("unable to parse: %v", badreqResponse[0].AttemptedValue)}
|
for _, response := range badRequestResponses {
|
||||||
return rejections, nil
|
rejections = append(rejections, response.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rejections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pushResponse := make([]PushResponse, 0)
|
pushResponse := make([]PushResponse, 0)
|
||||||
err = json.Unmarshal(res, &pushResponse)
|
if err = json.Unmarshal(res, &pushResponse); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,7 @@ func Test_client_Push(t *testing.T) {
|
||||||
Protocol: "torrent",
|
Protocol: "torrent",
|
||||||
PublishDate: "2021-08-21T15:36:00Z",
|
PublishDate: "2021-08-21T15:36:00Z",
|
||||||
}},
|
}},
|
||||||
rejections: []string{"unable to parse: Minx 1 epi 9 2160p"},
|
rejections: []string{"[error: ] Title: Unable to parse - got value: Minx 1 epi 9 2160p"},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,10 +78,15 @@ type PushResponse struct {
|
||||||
type BadRequestResponse struct {
|
type BadRequestResponse struct {
|
||||||
PropertyName string `json:"propertyName"`
|
PropertyName string `json:"propertyName"`
|
||||||
ErrorMessage string `json:"errorMessage"`
|
ErrorMessage string `json:"errorMessage"`
|
||||||
|
ErrorCode string `json:"errorCode"`
|
||||||
AttemptedValue string `json:"attemptedValue"`
|
AttemptedValue string `json:"attemptedValue"`
|
||||||
Severity string `json:"severity"`
|
Severity string `json:"severity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *BadRequestResponse) String() string {
|
||||||
|
return fmt.Sprintf("[%v: %v] %v: %v - got value: %v", r.Severity, r.ErrorCode, r.PropertyName, r.ErrorMessage, r.AttemptedValue)
|
||||||
|
}
|
||||||
|
|
||||||
type SystemStatusResponse struct {
|
type SystemStatusResponse struct {
|
||||||
AppName string `json:"appName"`
|
AppName string `json:"appName"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
@ -100,8 +105,7 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
||||||
c.Log.Printf("readarr system/status status: (%v) response: %v\n", status, string(res))
|
c.Log.Printf("readarr system/status status: (%v) response: %v\n", status, string(res))
|
||||||
|
|
||||||
response := SystemStatusResponse{}
|
response := SystemStatusResponse{}
|
||||||
err = json.Unmarshal(res, &response)
|
if err = json.Unmarshal(res, &response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,22 +121,23 @@ func (c *client) Push(release Release) ([]string, error) {
|
||||||
c.Log.Printf("readarr release/push status: (%v) response: %v\n", status, string(res))
|
c.Log.Printf("readarr release/push status: (%v) response: %v\n", status, string(res))
|
||||||
|
|
||||||
if status == http.StatusBadRequest {
|
if status == http.StatusBadRequest {
|
||||||
badreqResponse := make([]*BadRequestResponse, 0)
|
badRequestResponses := make([]*BadRequestResponse, 0)
|
||||||
err = json.Unmarshal(res, &badreqResponse)
|
|
||||||
if err != nil {
|
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
if badreqResponse[0] != nil && badreqResponse[0].PropertyName == "Title" && badreqResponse[0].ErrorMessage == "Unable to parse" {
|
rejections := []string{}
|
||||||
rejections := []string{fmt.Sprintf("unable to parse: %v", badreqResponse[0].AttemptedValue)}
|
for _, response := range badRequestResponses {
|
||||||
return rejections, err
|
rejections = append(rejections, response.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rejections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushResponse := make([]PushResponse, 0)
|
// pushResponse := make([]PushResponse, 0)
|
||||||
var pushResponse PushResponse
|
var pushResponse PushResponse
|
||||||
err = json.Unmarshal(res, &pushResponse)
|
if err = json.Unmarshal(res, &pushResponse); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,10 +78,15 @@ type PushResponse struct {
|
||||||
type BadRequestResponse struct {
|
type BadRequestResponse struct {
|
||||||
PropertyName string `json:"propertyName"`
|
PropertyName string `json:"propertyName"`
|
||||||
ErrorMessage string `json:"errorMessage"`
|
ErrorMessage string `json:"errorMessage"`
|
||||||
|
ErrorCode string `json:"errorCode"`
|
||||||
AttemptedValue string `json:"attemptedValue"`
|
AttemptedValue string `json:"attemptedValue"`
|
||||||
Severity string `json:"severity"`
|
Severity string `json:"severity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *BadRequestResponse) String() string {
|
||||||
|
return fmt.Sprintf("[%v: %v] %v: %v - got value: %v", r.Severity, r.ErrorCode, r.PropertyName, r.ErrorMessage, r.AttemptedValue)
|
||||||
|
}
|
||||||
|
|
||||||
type SystemStatusResponse struct {
|
type SystemStatusResponse struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
|
@ -99,8 +104,7 @@ func (c *client) Test() (*SystemStatusResponse, error) {
|
||||||
c.Log.Printf("sonarr system/status status: (%v) response: %v\n", status, string(res))
|
c.Log.Printf("sonarr system/status status: (%v) response: %v\n", status, string(res))
|
||||||
|
|
||||||
response := SystemStatusResponse{}
|
response := SystemStatusResponse{}
|
||||||
err = json.Unmarshal(res, &response)
|
if err = json.Unmarshal(res, &response); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,21 +120,22 @@ func (c *client) Push(release Release) ([]string, error) {
|
||||||
c.Log.Printf("sonarr release/push status: (%v) response: %v\n", status, string(res))
|
c.Log.Printf("sonarr release/push status: (%v) response: %v\n", status, string(res))
|
||||||
|
|
||||||
if status == http.StatusBadRequest {
|
if status == http.StatusBadRequest {
|
||||||
badreqResponse := make([]*BadRequestResponse, 0)
|
badRequestResponses := make([]*BadRequestResponse, 0)
|
||||||
err = json.Unmarshal(res, &badreqResponse)
|
|
||||||
if err != nil {
|
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
if badreqResponse[0] != nil && badreqResponse[0].PropertyName == "Title" && badreqResponse[0].ErrorMessage == "Unable to parse" {
|
rejections := []string{}
|
||||||
rejections := []string{fmt.Sprintf("unable to parse: %v", badreqResponse[0].AttemptedValue)}
|
for _, response := range badRequestResponses {
|
||||||
return rejections, err
|
rejections = append(rejections, response.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rejections, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pushResponse := make([]PushResponse, 0)
|
pushResponse := make([]PushResponse, 0)
|
||||||
err = json.Unmarshal(res, &pushResponse)
|
if err = json.Unmarshal(res, &pushResponse); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not unmarshal data")
|
return nil, errors.Wrap(err, "could not unmarshal data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue