Skip to content

Commit

Permalink
remove usage of github.com/pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Maser <[email protected]>
  • Loading branch information
TheMeier committed Jan 8, 2024
1 parent a6e62be commit 7139615
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions notify/rocketchat/rocketchat.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"os"
"strings"

"github.com/pkg/errors"
commoncfg "github.com/prometheus/common/config"

"github.com/prometheus/alertmanager/template"
Expand Down Expand Up @@ -224,14 +223,14 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
// classify them as retriable or not.
retry, err := n.retrier.Check(resp.StatusCode, resp.Body)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("channel %q", body.Channel))
err = fmt.Errorf("%w: channel %q", err, body.Channel)
return retry, notify.NewErrorWithReason(notify.GetFailureReasonFromStatusCode(resp.StatusCode), err)
}

// Rocketchat web API might return errors with a 200 response code.
retry, err = checkResponseError(resp)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("channel %q", body.Channel))
err = fmt.Errorf("%w: channel %q", err, body.Channel)
return retry, notify.NewErrorWithReason(notify.ClientErrorReason, err)
}

Expand All @@ -242,7 +241,7 @@ func (n *Notifier) Notify(ctx context.Context, as ...*types.Alert) (bool, error)
func checkResponseError(resp *http.Response) (bool, error) {
body, err := io.ReadAll(resp.Body)
if err != nil {
return true, errors.Wrap(err, "could not read response body")
return true, fmt.Errorf("%w: could not read response body: ", err)
}

return checkJSONResponseError(body)
Expand All @@ -258,7 +257,7 @@ func checkJSONResponseError(body []byte) (bool, error) {

var data response
if err := json.Unmarshal(body, &data); err != nil {
return true, errors.Wrapf(err, "could not unmarshal JSON response %q", string(body))
return true, fmt.Errorf("%w: could not unmarshal JSON response %q", err, string(body))
}
if !data.Success {
return false, fmt.Errorf("error response from Rocketchat: %s", data.Error)
Expand Down

0 comments on commit 7139615

Please sign in to comment.