1
0
Fork 0
hats/internal/util/resty.go

16 lines
390 B
Go

package util
import (
"fmt"
"github.com/go-resty/resty/v2"
)
// CheckSuccess wraps a resty request and if the status code is not 2XX will make the error non-nil
func CheckSuccess(resp *resty.Response, err error) (*resty.Response, error) {
if err == nil && !resp.IsSuccess() {
err = fmt.Errorf("%d status received: %s", resp.StatusCode(), string(resp.Body()))
}
return resp, err
}