- Notifications
You must be signed in to change notification settings - Fork 37
Closed
Description
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
Labels
No labels