src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

response.go (977B)


      1 package http
      2 
      3 import (
      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.
     10 type 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.
     16 type ResponseError struct {
     17 	Response *Response
     18 	Err      error
     19 }
     20 
     21 // HTTPStatusCode returns the HTTP response status code received from the service.
     22 func (e *ResponseError) HTTPStatusCode() int { return e.Response.StatusCode }
     23 
     24 // HTTPResponse returns the HTTP response received from the service.
     25 func (e *ResponseError) HTTPResponse() *Response { return e.Response }
     26 
     27 // Unwrap returns the nested error if any, or nil.
     28 func (e *ResponseError) Unwrap() error { return e.Err }
     29 
     30 func (e *ResponseError) Error() string {
     31 	return fmt.Sprintf(
     32 		"http response error StatusCode: %d, %v",
     33 		e.Response.StatusCode, e.Err)
     34 }