-
Notifications
You must be signed in to change notification settings - Fork 1.9k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling all possible errors from AWS / Boto #4103
Comments
Hi @Hvass-Labs thanks for reaching out. As mentioned in the error handling documentation that you referenced, it notes:
So while it is possible to account for each specific exception, And the full list of possible exceptions can be found in the exceptions.py file. For example BotoCoreError, which serves as a catchall for unspecified Botocore errors, but wouldn't account for things like networking-related errors. I hope that helps - if you have any more questions please let us know. Or if you are encountering issues other than |
Thanks for the detailed reply! I did actually read the doc-page and noticed the section you highlight :-) But it is still a bit unclear to me, so allow me to ask more specifically:
Thanks for the tip on logging the stack-trace. However, as this is running on a web-server, I don't log the stack-trace because I am worried it might contain the AWS account credentials, which I don't want in the log for security reasons. But perhaps I'm wrong? |
Thanks for following up and your patience. I think the snippet below helps show what you can do here. You can use import boto3
import botocore
ses_client = boto3.client("sesv2")
# Define the email parameters
# ...
try:
response = ses_client.send_email(
FromEmailAddress=sender_email,
Destination=destination,
Content=message
)
print("Email sent! Message ID:", response['MessageId'])
except botocore.exceptions.ClientError as error:
# Handle specific AWS service errors
if error.response['Error']['Code'] == 'MessageRejected':
print("Error: Message rejected by Amazon SES:", error.response['Error']['Message'])
else:
print("An error occurred while sending the email:", error)
except botocore.exceptions.ParamValidationError as error:
raise ValueError('The parameters you provided are incorrect: {}'.format(error))
except Exception as error:
# Handle any other exceptions
print("An unexpected error occurred:", error) Also in case you didn't see it I will highlight this section on parsing error responses, with I think this part being the most relevant here:
So as long as you're catching For more information on logging please see the boto3.set_stream_logger documentation. As mentioned there:
But also note the Warning:
|
Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one. |
Thanks for the example. Maybe I am being a stickler, but I'm still not sure it answers my two questions above :-) Would it be possible to give yes / no answers to those two questions? My project is running on a web-server where I give broad error-messages to the user for different kinds of error-types. I am catching both |
Sure I'll try to clarify:
No - to catch every exception, you would need to catch every documented exception. As mentioned in the docs,
No - it isn't necessary to also check for HTTP error codes. But depending on the service/API and your use case, you may want to check. For example with SNS the PublishBatch API documentation says:
In the case of S3 copy requests, if an error is found with a 200 status code then it is changed here to 500. Converting this to a Q&A discussion. If you want to create a new issue with a specific request please feel free to. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Describe the issue
Hello,
I am using AWS SES to send e-mails. I am new to AWS and it is unclear from the docs how to handle all possible errors arising from AWS / Boto, so they can be logged and investigated later. The user doesn't need to know exactly what happened and will just see a generic error-message.
My code is essentially:
Are these two exception classes sufficient to handle all possible errors arising in AWS / Boto?
Or do I also need to inspect the
response
object for other possible errors if the HTTP status-code isn't 200 for success?Thanks!
Links
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/error-handling.html
The text was updated successfully, but these errors were encountered: