@@ -214,17 +214,16 @@ class CSEClient:
|
||||
operation: str,
|
||||
request_error_message: str,
|
||||
) -> None:
|
||||
for prop in root.properties:
|
||||
if prop.key == "Error":
|
||||
codes = [item.value for item in prop.items if item.value]
|
||||
log.warning(
|
||||
"cse_response_error",
|
||||
operation=operation,
|
||||
error_codes=codes,
|
||||
)
|
||||
raise CSERequestError(
|
||||
f"{request_error_message} application error {codes}."
|
||||
)
|
||||
error_codes = _response_error_codes(root)
|
||||
if error_codes:
|
||||
log.warning(
|
||||
"cse_response_error",
|
||||
operation=operation,
|
||||
error_codes=error_codes,
|
||||
)
|
||||
raise CSERequestError(
|
||||
f"{request_error_message} application error {error_codes}."
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _should_retry(status_code: int) -> bool:
|
||||
@@ -238,6 +237,20 @@ def _response_excerpt(text: str, *, limit: int = 1000) -> str:
|
||||
return " ".join(text.split())[:limit]
|
||||
|
||||
|
||||
def _response_error_codes(root: Element) -> list[str]:
|
||||
codes: list[str] = []
|
||||
_collect_response_error_codes(root, codes)
|
||||
return codes
|
||||
|
||||
|
||||
def _collect_response_error_codes(element: Element, codes: list[str]) -> None:
|
||||
for prop in element.properties:
|
||||
if prop.key == "Error":
|
||||
codes.extend(item.value for item in prop.items if item.value)
|
||||
for child in (*element.items, *element.tables):
|
||||
_collect_response_error_codes(child, codes)
|
||||
|
||||
|
||||
class CSEProvider(DeliveryProvider):
|
||||
name = CSE_PROVIDER_NAME
|
||||
|
||||
|
||||
Reference in New Issue
Block a user