From 4148784daa6c3c7afa8d63e1e01494378fd4e323 Mon Sep 17 00:00:00 2001 From: mptap Date: Sat, 28 Oct 2017 15:50:55 -0700 Subject: [PATCH 1/2] Documented the new error handling functionality from python-http-client --- TROUBLESHOOTING.md | 6 ++++++ USE_CASES.md | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 9988524ca..a68431ae5 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -12,6 +12,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se * [Using the Package Manager](#package-manager) * [Version Convention](#versions) * [Viewing the Request Body](#request-body) +* [Error Handling](#error-handling) ## Environment Variables and Your SendGrid API Key @@ -106,3 +107,8 @@ You can do this right before you call `response = sg.client.mail.send.post(reque ```python print mail.get() ``` + + +# Error Handling + +Please review [our use_cases](https://github.com/sendgrid/sendgrid-python/USE_CASES.md) for examples of error handling. diff --git a/USE_CASES.md b/USE_CASES.md index 810d345ca..4bb7261ac 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -7,6 +7,7 @@ This documentation provides examples for specific use cases. Please [open an iss * [How to Setup a Domain Whitelabel](#domain_whitelabel) * [How to View Email Statistics](#email_stats) * [Asynchronous Mail Send](#asynchronous-mail-send) +* [Error Handling](#error-handling) # Transactional Templates @@ -272,3 +273,28 @@ if __name__ == "__main__": loop.run_until_complete(task) ``` + +# Error Handling +Custom exceptions for `python_http_client` are now supported which can be imported by consuming libraries. + +```python + import sendgrid + import os + from sendgrid.helpers.mail import * + from python_http_client import exceptions + + sg = sendgrid.SendGridAPIClient(apikey=os.environ.get('SENDGRID_API_KEY')) + from_email = Email("dx@sendgrid.com") + to_email = Email("elmer.thomas@sendgrid.com") + subject = "Sending with SendGrid is Fun" + content = Content("text/plain", "and easy to do anywhere, even with Python") + mail = Mail(from_email, subject, to_email, content) + try: + response = sg.client.mail.send.post(request_body=mail.get()) + except exceptions.BadRequestsError as e: + print(e.body) + exit() + print(response.status_code) + print(response.body) + print(response.headers) +``` From f15bb996962ec21677ac3454add4a7006dd2578c Mon Sep 17 00:00:00 2001 From: Elmer Thomas Date: Sun, 29 Oct 2017 13:27:23 -0700 Subject: [PATCH 2/2] Update USE_CASES.md --- USE_CASES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/USE_CASES.md b/USE_CASES.md index 4bb7261ac..11dd594b0 100644 --- a/USE_CASES.md +++ b/USE_CASES.md @@ -275,7 +275,9 @@ if __name__ == "__main__": # Error Handling -Custom exceptions for `python_http_client` are now supported which can be imported by consuming libraries. +[Custom exceptions](https://github.com/sendgrid/python-http-client/blob/master/python_http_client/exceptions.py) for `python_http_client` are now supported, which can be imported by consuming libraries. + +Please see [here](https://github.com/sendgrid/python-http-client/blob/master/python_http_client/exceptions.py) for a list of supported exceptions. ```python import sendgrid