55 "context"
66 "encoding"
77 "encoding/xml"
8+ "errors"
89 "net/http"
910 "strconv"
1011
@@ -32,8 +33,8 @@ func (e *HTTPError) Error() string {
3233}
3334
3435func (e * HTTPError ) StatusCode () int {
35- //nolint:errorlint
36- if sc , ok := e .err .( StatusCoder ); ok {
36+ var sc StatusCoder
37+ if errors . As ( e .err , & sc ) {
3738 return sc .StatusCode ()
3839 }
3940
@@ -45,25 +46,44 @@ func (e *HTTPError) StatusCode() int {
4546}
4647
4748func (e * HTTPError ) MarshalText () ([]byte , error ) {
49+ var m encoding.TextMarshaler
50+ if errors .As (e .err , & m ) {
51+ return m .MarshalText ()
52+ }
53+
4854 return []byte (e .Error ()), nil
4955}
5056
5157func (e * HTTPError ) MarshalJSON () ([]byte , error ) {
52- var buf bytes.Buffer
58+ var m json.Marshaler
59+ if errors .As (e .err , & m ) {
60+ return m .MarshalJSON ()
61+ }
5362
63+ var buf bytes.Buffer
5464 buf .WriteString (`{"message":` )
5565 buf .WriteString (strconv .Quote (e .Error ()))
5666 buf .WriteRune ('}' )
5767
5868 return buf .Bytes (), nil
5969}
6070
61- func (e * HTTPError ) MarshalXML (enc * xml.Encoder , _ xml.StartElement ) error {
62- start := xml.StartElement {Name : xml.Name {Local : "message" }}
71+ func (e * HTTPError ) MarshalXML (enc * xml.Encoder , start xml.StartElement ) error {
72+ var m xml.Marshaler
73+ if errors .As (e .err , & m ) {
74+ return m .MarshalXML (enc , start )
75+ }
76+
77+ start = xml.StartElement {Name : xml.Name {Local : "message" }}
6378 return enc .EncodeElement (e .Error (), start )
6479}
6580
6681func (e * HTTPError ) MarshalYAML () (interface {}, error ) {
82+ var m yaml.Marshaler
83+ if errors .As (e .err , & m ) {
84+ return m .MarshalYAML ()
85+ }
86+
6787 return map [string ]string {"message" : e .Error ()}, nil
6888}
6989
0 commit comments