Skip to content

Commit 7a71074

Browse files
authored
add logic to deal with xml format in return error (#9142)
* add logic to deal with xml format in return error * change as per comments * change version * code style * change version
1 parent 08743ff commit 7a71074

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/spring/HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Release History
22
===============
3+
1.28.4
4+
---
5+
* Fix regression issue caused by the SDK change.
6+
37
1.28.3
48
---
59
* Update Azure Spring Apps reference doc.

src/spring/azext_spring/_utils.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# --------------------------------------------------------------------------------------------
55
import json
66
import re
7+
import xml.etree.ElementTree as ET
78
from datetime import datetime
89
from enum import Enum
910
import os
@@ -334,10 +335,32 @@ def handle_asc_exception(ex):
334335
try:
335336
raise CLIError(ex.inner_exception.error.message)
336337
except AttributeError:
338+
logger.debug(f"CLIError ex: {ex}")
339+
logger.debug(f"CLIError ex.response.internal_response.text: {ex.response.internal_response.text}")
337340
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"])
341+
logger.debug("CLIError: Trying to parse the exception message.")
342+
try:
343+
response_dict = json.loads(ex.response.internal_response.text)
344+
logger.debug(f"CLIError response_dict: {response_dict}")
345+
raise CLIError(response_dict["error"]["message"])
346+
except json.JSONDecodeError:
347+
# Try to extract error from XML format
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.debug("CLIError: Unable to parse the exception message.")
341364
raise CLIError(ex)
342365

343366

src/spring/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# TODO: Confirm this is the right version number you want and it matches your
1818
# HISTORY.rst entry.
19-
VERSION = '1.28.3'
19+
VERSION = '1.28.4'
2020

2121
# The full list of classifiers is available at
2222
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)