mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 21:33:22 +01:00
notif: enhance error message for JSON decode response issues
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user