response.go

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