Hi, I think the code in many cases is unnecessarily verbose. For example the function output_webfault_errors() could be written without repeating the same code blocks:
error_types = (
["ApiFault", "OperationErrors", "OperationError"],
["ApiFaultDetail", "Errors", "AdApiError"],
["ApiFaultDetail", "BatchErrors", "BatchError"],
["EditorialApiFaultDetail", "EditorialErrors", "EditorialError"],
["EditorialApiFaultDetail", "OperationErrors", "OperationError"],
["ExceptionDetail"],
)
def handle_error(detail, fields):
api_errors = detail
for field in fields:
api_errors = getattr(api_errors, field, None)
if api_errors is not None:
if isinstance(api_errors, list):
for api_error in api_errors:
output_bing_ads_webfault_error(api_error)
else:
output_bing_ads_webfault_error(api_errors)
return True
return False
def output_webfault_errors(ex):
if not hasattr(ex.fault, "detail"):
raise Exception("Unknown WebFault")
for et in error_types:
if handle_error(ex.fault.detail, et):
return
raise Exception("Unknown WebFault")
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: c6b1a054-c617-7cd5-ff30-1608ee747756
Version Independent ID: ff8c8e06-7ae0-b6a9-c9dc-4d4a534027a2
Hi, I think the code in many cases is unnecessarily verbose. For example the function output_webfault_errors() could be written without repeating the same code blocks:
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.