@@ -334,10 +334,33 @@ def handle_asc_exception(ex):
334334 try :
335335 raise CLIError (ex .inner_exception .error .message )
336336 except AttributeError :
337+ logger .warning (f"CLIError ex: { ex } " )
338+ logger .warning (f"CLIError ex.response.internal_response.text: { ex .response .internal_response .text } " )
337339 if hasattr (ex , 'response' ) and ex .response .internal_response .text :
338- response_dict = json .loads (ex .response .internal_response .text )
339- raise CLIError (response_dict ["error" ]["message" ])
340+ logger .warning ("CLIError: Trying to parse the exception message." )
341+ try :
342+ response_dict = json .loads (ex .response .internal_response .text )
343+ logger .warning (f"CLIError response_dict: { response_dict } " )
344+ raise CLIError (response_dict ["error" ]["message" ])
345+ except json .JSONDecodeError :
346+ # Try to extract error from XML format
347+ import xml .etree .ElementTree as ET
348+ try :
349+ root = ET .fromstring (ex .response .internal_response .text )
350+ # Look for common error message patterns in XML
351+ error_msg = root .find ('.//Message' )
352+ if error_msg is not None and error_msg .text :
353+ raise CLIError (error_msg .text )
354+ # If no Message element, try to find any text content
355+ error_text = '' .join (root .itertext ()).strip ()
356+ if error_text :
357+ raise CLIError (error_text )
358+ except ET .ParseError :
359+ pass
360+ # If both JSON and XML parsing fail, return the raw text
361+ raise CLIError (ex .response .internal_response .text )
340362 else :
363+ logger .warning ("CLIError: Unable to parse the exception message." )
341364 raise CLIError (ex )
342365
343366
0 commit comments