feat(download-clients): improve arr error handling (#549)

This commit is contained in:
ze0s 2022-11-19 16:20:48 +01:00 committed by GitHub
parent 33aa21fc15
commit 301180e55b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 42 deletions

View file

@ -78,10 +78,15 @@ type PushResponse struct {
type BadRequestResponse struct {
PropertyName string `json:"propertyName"`
ErrorMessage string `json:"errorMessage"`
ErrorCode string `json:"errorCode"`
AttemptedValue string `json:"attemptedValue"`
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 {
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))
response := SystemStatusResponse{}
err = json.Unmarshal(res, &response)
if err != nil {
if err = json.Unmarshal(res, &response); err != nil {
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))
if status == http.StatusBadRequest {
badreqResponse := make([]*BadRequestResponse, 0)
err = json.Unmarshal(res, &badreqResponse)
if err != nil {
badRequestResponses := make([]*BadRequestResponse, 0)
if err = json.Unmarshal(res, &badRequestResponses); err != nil {
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{fmt.Sprintf("unable to parse: %v", badreqResponse[0].AttemptedValue)}
return rejections, err
rejections := []string{}
for _, response := range badRequestResponses {
rejections = append(rejections, response.String())
}
return rejections, nil
}
pushResponse := make([]PushResponse, 0)
err = json.Unmarshal(res, &pushResponse)
if err != nil {
if err = json.Unmarshal(res, &pushResponse); err != nil {
return nil, errors.Wrap(err, "could not unmarshal data")
}