Use is_boto3_error_code in 'standard' example (#72313)
Use is_boto3_error_code in 'standard' example rather than e.response['Error']['Code'] (#72313) Co-authored-by: Sloane Hertel <shertel@redhat.com>
This commit is contained in:
parent
cf08c23b4f
commit
63afb33d86
1 changed files with 5 additions and 7 deletions
|
@ -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
|
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.
|
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
|
.. 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']
|
name = module.params.get['name']
|
||||||
try:
|
try:
|
||||||
result = connection.describe_frooble(FroobleName=name)
|
result = connection.describe_frooble(FroobleName=name)
|
||||||
except botocore.exceptions.ClientError as e:
|
except is_boto3_error_code('FroobleNotFound'):
|
||||||
if e.response['Error']['Code'] == 'FroobleNotFound':
|
|
||||||
workaround_failure() # This is an error that we can work around
|
workaround_failure() # This is an error that we can work around
|
||||||
else:
|
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)
|
|
||||||
except botocore.exceptions.BotoCoreError as e:
|
|
||||||
module.fail_json_aws(e, msg="Couldn't obtain frooble %s" % name)
|
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
|
using fail_json() and avoiding ansible_collections.amazon.aws.plugins.module_utils.core
|
||||||
|
|
Loading…
Reference in a new issue