Skip to content
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

Built in EventDispatch silently fails #139

Closed
allanlei opened this issue Aug 29, 2018 · 2 comments
Closed

Built in EventDispatch silently fails #139

allanlei opened this issue Aug 29, 2018 · 2 comments

Comments

@allanlei
Copy link

The default EventDispatcher only handles network related errors and ignores HTTP errors(500, 503, etc) without any logging messages

try:
  if event.http_verb == enums.HTTPVerbs.GET:
    requests.get(event.url, params=event.params, timeout=10)
  elif event.http_verb == enums.HTTPVerbs.POST:
    requests.post(event.url, json=event.params, headers=event.headers, timeout=10)
except request_exception.RequestException as error:
  logging.error('Dispatch event failed. Error: %s' % str(error))

HTTP errors in requests do not raise Exceptions

In [2]: requests.get('https://httpbin.org/status/500')
Out[2]: <Response [500]>   # This is an object, not an raise error therefore not caught by try/except

You would need to raise from the response

response = requests.get(event.url, params=event.params, timeout=10)
In [4]: response.raise_for_status()
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-4-46d4bf99ee16> in <module>()
----> 1 requests.get('https://httpbin.org/status/500').raise_for_status()

python3.6/site-packages/requests/models.py in raise_for_status(self)
    937 
    938         if http_error_msg:
--> 939             raise HTTPError(http_error_msg, response=self)
    940 
    941     def close(self):

HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: https://httpbin.org/status/500
@aliabbasrizvi
Copy link
Contributor

Hi @allanlei. Thank you for logging this issue. Will take a look at this.

@aliabbasrizvi
Copy link
Contributor

@allanlei this issue was fixed in #140 and will be available in next release of the SDK.

Closing this issue and will comment when next release is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants