1package http
2
3import (
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.
12type 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
20func (e *ResponseError) ServiceRequestID() string { return e.RequestID }
21
22// Error returns the formatted error
23func (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)
31func (e *ResponseError) As(target interface{}) bool {
32	return errors.As(e.ResponseError, target)
33}
34