Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sendgrid/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import urllib.request as urllib_request
from urllib.parse import urlencode
from urllib.error import HTTPError
from urllib.error import URLError
except ImportError: # Python 2
import urllib2 as urllib_request
from urllib2 import HTTPError
from urllib2 import URLError
from urllib import urlencode

from .exceptions import SendGridClientError, SendGridServerError
Expand Down Expand Up @@ -121,6 +123,8 @@ def _legacy_send(self, message):
return self._make_request(message)
except HTTPError as e:
return e.code, e.read()
except URLError as e:
return 408, e.reason
except timeout as e:
return 408, e

Expand All @@ -134,5 +138,7 @@ def _raising_send(self, message):
raise SendGridServerError(e.code, e.read())
else:
assert False
except URLError as e:
raise SendGridClientError(408, 'Request timeout')
except timeout as e:
raise SendGridClientError(408, 'Request timeout')