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

16 lines
390 B
Go
Raw Permalink Normal View History

2023-11-10 23:22:46 +00:00
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
}