response.go 977 B

12345678910111213141516171819202122232425262728293031323334
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. )
  6. // Response provides the HTTP specific response structure for HTTP specific
  7. // middleware steps to use to deserialize the response from an operation call.
  8. type Response struct {
  9. *http.Response
  10. }
  11. // ResponseError provides the HTTP centric error type wrapping the underlying
  12. // error with the HTTP response value.
  13. type ResponseError struct {
  14. Response *Response
  15. Err error
  16. }
  17. // HTTPStatusCode returns the HTTP response status code received from the service.
  18. func (e *ResponseError) HTTPStatusCode() int { return e.Response.StatusCode }
  19. // HTTPResponse returns the HTTP response received from the service.
  20. func (e *ResponseError) HTTPResponse() *Response { return e.Response }
  21. // Unwrap returns the nested error if any, or nil.
  22. func (e *ResponseError) Unwrap() error { return e.Err }
  23. func (e *ResponseError) Error() string {
  24. return fmt.Sprintf(
  25. "http response error StatusCode: %d, %v",
  26. e.Response.StatusCode, e.Err)
  27. }