Merge pull request #1309 from crazy-max/notif-ret-http-error

notif: enhance error message for JSON decode response issues
This commit is contained in:
CrazyMax
2024-12-19 01:14:07 +01:00
committed by GitHub
3 changed files with 6 additions and 11 deletions

View File

@@ -114,9 +114,8 @@ func (c *Client) Send(entry model.NotifEntry) error {
ErrorCode int `json:"errorCode"` ErrorCode int `json:"errorCode"`
ErrorDescription string `json:"errorDescription"` ErrorDescription string `json:"errorDescription"`
} }
err := json.NewDecoder(resp.Body).Decode(&errBody) if err := json.NewDecoder(resp.Body).Decode(&errBody); err != nil {
if err != nil { return errors.Wrapf(err, "cannot decode JSON error response for HTTP %d %s status", resp.StatusCode, http.StatusText(resp.StatusCode))
return err
} }
return errors.Errorf("%d %s: %s", errBody.ErrorCode, errBody.Error, errBody.ErrorDescription) return errors.Errorf("%d %s: %s", errBody.ErrorCode, errBody.Error, errBody.ErrorDescription)
} }

View File

@@ -108,9 +108,8 @@ func (c *Client) Send(entry model.NotifEntry) error {
ErrorCode int `json:"errorCode"` ErrorCode int `json:"errorCode"`
ErrorDescription string `json:"errorDescription"` ErrorDescription string `json:"errorDescription"`
} }
err := json.NewDecoder(resp.Body).Decode(&errBody) if err := json.NewDecoder(resp.Body).Decode(&errBody); err != nil {
if err != nil { return errors.Wrapf(err, "cannot decode JSON error response for HTTP %d %s status", resp.StatusCode, http.StatusText(resp.StatusCode))
return err
} }
return errors.Errorf("%d %s: %s", errBody.ErrorCode, errBody.Error, errBody.ErrorDescription) return errors.Errorf("%d %s: %s", errBody.ErrorCode, errBody.Error, errBody.ErrorDescription)
} }

View File

@@ -147,14 +147,11 @@ func (c *Client) Send(entry model.NotifEntry) error {
Error string `json:"error,omitempty"` Error string `json:"error,omitempty"`
ErrorType string `json:"errorType,omitempty"` ErrorType string `json:"errorType,omitempty"`
} }
err = json.NewDecoder(resp.Body).Decode(&respBody) if err = json.NewDecoder(resp.Body).Decode(&respBody); err != nil {
if err == nil { return errors.Wrapf(err, "cannot decode JSON body response for HTTP %d %s status", resp.StatusCode, http.StatusText(resp.StatusCode))
return err
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.Errorf("unexpected HTTP error %d: %s", resp.StatusCode, respBody.ErrorType) return errors.Errorf("unexpected HTTP error %d: %s", resp.StatusCode, respBody.ErrorType)
} }
return nil return nil
} }