@@ -89,10 +89,8 @@ func parseJSONResponse(bodyBytes []byte, apiError *APIError) {
89
89
90
90
// parseXMLResponse dynamically parses XML error responses and accumulates potential error messages.
91
91
func parseXMLResponse (bodyBytes []byte , apiError * APIError ) {
92
- // Always set the Raw field to the entire XML content for debugging purposes.
93
92
apiError .RawResponse = string (bodyBytes )
94
93
95
- // Parse the XML document.
96
94
doc , err := xmlquery .Parse (bytes .NewReader (bodyBytes ))
97
95
if err != nil {
98
96
return
@@ -111,7 +109,6 @@ func parseXMLResponse(bodyBytes []byte, apiError *APIError) {
111
109
112
110
traverse (doc )
113
111
114
- // Concatenate all messages found in the XML for the 'Message' field of APIError.
115
112
if len (messages ) > 0 {
116
113
apiError .Message = strings .Join (messages , "; " )
117
114
} else {
@@ -122,29 +119,23 @@ func parseXMLResponse(bodyBytes []byte, apiError *APIError) {
122
119
123
120
// parseTextResponse updates the APIError structure based on a plain text error response and logs it.
124
121
func parseTextResponse (bodyBytes []byte , apiError * APIError ) {
125
- // Convert the body bytes to a string and assign it to both the message and RawResponse fields of APIError.
126
122
bodyText := string (bodyBytes )
127
123
apiError .RawResponse = bodyText
128
-
129
- // Directly use the body text as the error message if the Message field is empty.
130
124
apiError .Message = bodyText
131
-
132
125
}
133
126
134
127
// parseHTMLResponse extracts meaningful information from an HTML error response,
135
128
// concatenating all text within <p> tags and links found within them.
136
129
func parseHTMLResponse (bodyBytes []byte , apiError * APIError ) {
137
- // Set the entire HTML content as the RawResponse for debugging purposes.
138
130
apiError .RawResponse = string (bodyBytes )
139
131
140
- // Parse the HTML document.
141
132
reader := bytes .NewReader (bodyBytes )
142
133
doc , err := html .Parse (reader )
143
134
if err != nil {
144
135
return
145
136
}
146
137
147
- var messages []string // To accumulate messages and links.
138
+ var messages []string
148
139
var parse func (* html.Node )
149
140
parse = func (n * html.Node ) {
150
141
if n .Type == html .ElementNode && n .Data == "p" {
0 commit comments