github.com/helmwave/helmwave@v0.36.4-0.20240509190856-b35563eba4c6/pkg/monitor/http/errors.go (about) 1 package http 2 3 import ( 4 "errors" 5 "fmt" 6 ) 7 8 var ErrURLEmpty = errors.New("URL cannot be empty") 9 10 type RequestError struct { 11 Err error 12 } 13 14 func NewRequestError(err error) error { 15 return &RequestError{Err: err} 16 } 17 18 func (err RequestError) Error() string { 19 return fmt.Sprintf("failed to create HTTP request: %s", err.Err) 20 } 21 22 func (err RequestError) Unwrap() error { 23 return err.Err 24 } 25 26 type ResponseError struct { 27 Err error 28 } 29 30 func NewResponseError(err error) error { 31 return &ResponseError{Err: err} 32 } 33 34 func (err ResponseError) Error() string { 35 return fmt.Sprintf("failed to get HTTP response: %s", err.Err) 36 } 37 38 func (err ResponseError) Unwrap() error { 39 return err.Err 40 } 41 42 type UnexpectedStatusError struct { 43 StatusCode int 44 } 45 46 func NewUnexpectedStatusError(status int) error { 47 return &UnexpectedStatusError{StatusCode: status} 48 } 49 50 func (err UnexpectedStatusError) Error() string { 51 return fmt.Sprintf("unexpected status code %d", err.StatusCode) 52 }