github.com/cobalt77/jfrog-client-go@v0.14.5/utils/errorutils/errorutils.go (about)

     1  package errorutils
     2  
     3  import (
     4  	"errors"
     5  	"io/ioutil"
     6  	"net/http"
     7  )
     8  
     9  // Error modes (how should the application behave when the CheckError function is invoked):
    10  type OnErrorHandler func(error) error
    11  
    12  var CheckError = func(err error) error {
    13  	return err
    14  }
    15  
    16  // Check expected status codes and return error if needed
    17  func CheckResponseStatus(resp *http.Response, expectedStatusCodes ...int) error {
    18  	for _, statusCode := range expectedStatusCodes {
    19  		if statusCode == resp.StatusCode {
    20  			return nil
    21  		}
    22  	}
    23  
    24  	errorBody, _ := ioutil.ReadAll(resp.Body)
    25  	return errors.New(resp.Status + " " + string(errorBody))
    26  }