-
Notifications
You must be signed in to change notification settings - Fork 723
sendgrid-python should define it's own Error class #315
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
Comments
Hi @w- ! I was working on the same thing with ref to the issue #224. We can define a custom SendGrid exception. |
Hi @dibyadas , My specific case here is that there is no way to handle an erronous HTTP response because the underlying urllib will always throw an HTTPError. IMHO, we should have a specific Error class that represents specifically when the API call returns an non-success HTTP Response. I have not given much thought to the handling of other errors such as the example you provide "where an email request with empty content or empty subject". I just think those are a seperate class of errors. The sendgrid API V3 documentation outlines how the API returns relatively rich error information with the body of the response often outlining specific issues with the API request. Given the specific implementation of sendgrid-python and python-http-client I'm not sure what the best way to achieve this would be. |
@thinkingserious thanks for taking a look at this. |
Please see the comment I made here. Thanks for taking the time to help out with your feedback, we greatly appreciate it! |
I'd like to resurrect this issue as This means, as @w- pointed out, library users must be knowledgeable of an implementation detail ( Due to this library users must declare IMO ideally import sendgrid
from sendgrid.helpers.mail import *
sg = sendgrid.SendGridAPIClient(apikey='foobar')
from_email = Email('foo@bar.com', name='Foo')
to_email = Email('qux@baz.net', name = 'Qux')
subject = 'my subject'
content = Content('text/html', 'some html here')
mail = Mail(from_email, subject, to_email, content)
try:
response = sg.client.mail.send.post(request_body=mail.get())
except sendgrid.exceptions.HTTPError as e:
print(e.read()) |
Thanks for the heads up @phrohdoh! This issue is officially resurrected :) |
If it's still worth it, I would like to have a go at it. |
Hi @hundredrab, It's all yours, but please make your contribution to the v4 branch. Thanks! With Best Regards, Elmer |
Since there has been no activity on this issue since March 1, 2020, we are closing this issue. Please feel free to reopen or create a new issue if you still require assistance. Thank you! |
Issue Summary
related to sendgrid/python-http-client#16
Crurently if an application/library consumes sendgrid-python and an API request surfaces a HTTP error, it raises a urllib HTTPError.
Now, in order to handle this specific error, the consuming application needs to import urllib.
Ideally, a consuming application only needs to know about sendgrid-python and not the underlying implementation of python-http-client or urllib in order to handle common place http errors.
Steps to Reproduce
Technical details:
The text was updated successfully, but these errors were encountered: