django - Properly catch boto3 Errors -
i developing django app communicates several amazon web services.
so far having trouble dealing , catching exceptions thrown boto3 client. doing seems unnecessarily tedious:
example:
client = boto3.client('sns') client.create_platform_endpoint(platformapplicationarn=sns_app_arn, token=token)
this might throw botocore.errorfactory.invalidparameterexception
if e.g. token bad.
client.get_endpoint_attributes(endpointarn=endpoint_arn)
might throw botocore.errorfactory.notfoundexception
.
first, can't find these errors anywhere in code, generated somewhere. bottom line: can't import , catch usual.
second, found 1 way catch error here using:
try: # boto3 stuff except botocore.exceptions.clienterror e: if e.response['error']['code'] == 'notfound': # handle exception else: raise e
but have remove exception
part of error name. seems random , have no clue whether remove error
in botocore.exceptions.paramvalidationerror
if wanted catch one. it's hard generalize.
another way catch error using boto3 client object got:
try: # boto3 stuff except client.exceptions.notfoundexception e: # handle exception
this seems cleanest way far. don't have boto3 client object @ hand want catch error. still trying things out, it's guess work.
does know how boto3 errors supposed handled?
or can point me towards coherent documentation mentions errors above? thanks
Comments
Post a Comment