diff --git a/docs/docsite/rst/dev_guide/platforms/aws_guidelines.rst b/docs/docsite/rst/dev_guide/platforms/aws_guidelines.rst index 27cafb722fa..ffc41b26d14 100644 --- a/docs/docsite/rst/dev_guide/platforms/aws_guidelines.rst +++ b/docs/docsite/rst/dev_guide/platforms/aws_guidelines.rst @@ -287,7 +287,8 @@ amounts of exception handling to existing modules, we recommend migrating the mo Note that it should normally be acceptable to catch all normal exceptions here, however if you expect anything other than botocore exceptions you should test everything works as expected. -If you need to perform an action based on the error boto3 returned, use the error code. +If you need to perform an action based on the error boto3 returned, use the error code and the +``is_boto3_error_code()`` helper. .. code-block:: python @@ -295,12 +296,9 @@ If you need to perform an action based on the error boto3 returned, use the erro name = module.params.get['name'] try: result = connection.describe_frooble(FroobleName=name) - except botocore.exceptions.ClientError as e: - if e.response['Error']['Code'] == 'FroobleNotFound': - workaround_failure() # This is an error that we can work around - else: - module.fail_json_aws(e, msg="Couldn't obtain frooble %s" % name) - except botocore.exceptions.BotoCoreError as e: + except is_boto3_error_code('FroobleNotFound'): + workaround_failure() # This is an error that we can work around + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: # pylint: disable=duplicate-except module.fail_json_aws(e, msg="Couldn't obtain frooble %s" % name) using fail_json() and avoiding ansible_collections.amazon.aws.plugins.module_utils.core