@@ -294,16 +294,29 @@ func (u *JamfAPIHandler) UnmarshalResponse(resp *http.Response, out interface{},
294
294
}
295
295
}
296
296
*/
297
- if strings .Contains (contentType , "text/html" ) {
298
- htmlErrorMessages := ExtractErrorMessageFromHTML (string (bodyBytes ))
297
+ // Handle any errors that occurred during unmarshaling
298
+ if err != nil {
299
+ // If unmarshalling fails, check if the content might be HTML
300
+ if strings .Contains (string (bodyBytes ), "<html>" ) {
301
+ htmlErrorMessages := ExtractErrorMessageFromHTML (string (bodyBytes ))
299
302
300
- for _ , msg := range htmlErrorMessages {
301
- for key , value := range msg {
302
- log .Error ("HTML Error" , zap .String (key , value ))
303
+ // Combine all HTML error messages into a single string
304
+ var combinedErrMsgs []string
305
+ for _ , msg := range htmlErrorMessages {
306
+ for _ , value := range msg {
307
+ combinedErrMsgs = append (combinedErrMsgs , value )
308
+ }
303
309
}
304
- }
310
+ combinedErrMsg := strings .Join (combinedErrMsgs , "; " )
311
+
312
+ // Log the combined error message as a single entry
313
+ log .Error ("Received HTML content instead of expected format" ,
314
+ zap .String ("error_message" , combinedErrMsg ),
315
+ zap .Int ("status_code" , resp .StatusCode ),
316
+ )
305
317
306
- return fmt .Errorf ("HTML error encountered" )
318
+ return fmt .Errorf ("received HTML content instead of expected format: %s" , combinedErrMsg )
319
+ }
307
320
}
308
321
309
322
// Check for non-success status codes before attempting to unmarshal
0 commit comments