Skip to content

Built in EventDispatch silently fails #139

Closed
@allanlei

Description

@allanlei

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions