src

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

response_error.go (963B)


      1 package http
      2 
      3 import (
      4 	"errors"
      5 	"fmt"
      6 
      7 	smithyhttp "github.com/aws/smithy-go/transport/http"
      8 )
      9 
     10 // ResponseError provides the HTTP centric error type wrapping the underlying error
     11 // with the HTTP response value and the deserialized RequestID.
     12 type ResponseError struct {
     13 	*smithyhttp.ResponseError
     14 
     15 	// RequestID associated with response error
     16 	RequestID string
     17 }
     18 
     19 // ServiceRequestID returns the request id associated with Response Error
     20 func (e *ResponseError) ServiceRequestID() string { return e.RequestID }
     21 
     22 // Error returns the formatted error
     23 func (e *ResponseError) Error() string {
     24 	return fmt.Sprintf(
     25 		"https response error StatusCode: %d, RequestID: %s, %v",
     26 		e.Response.StatusCode, e.RequestID, e.Err)
     27 }
     28 
     29 // As populates target and returns true if the type of target is a error type that
     30 // the ResponseError embeds, (e.g.AWS HTTP ResponseError)
     31 func (e *ResponseError) As(target interface{}) bool {
     32 	return errors.As(e.ResponseError, target)
     33 }