Skip to content
Myr

Now, safe_mode will catch socket.timeout too.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Josh Imhoff · committed by Josh Imhoff · parent cff70e7 · Browse files · 1 file+3 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+3 added−2 removed

  • other:+3 added−2 removed

1 file+3 added−2 removed

modified:requests/safe_mode.py+3 added-2 removed
10 unmodified lines
1112"""1314from .models import Response15from .exceptions import RequestException, ConnectionError, HTTPError15from .packages.urllib3.response import HTTPResponse16from .exceptions import RequestException, ConnectionError, HTTPError17import socket1819def catch_exceptions_if_in_safe_mode(function):20 """New implementation of safe_mode. We catch all exceptions at the API level21 and then return a blank Response object with the error field filled. This decorator
5 unmodified lines
27 if (kwargs.get('config') and kwargs.get('config').get('safe_mode')) or (kwargs.get('session') 28 and kwargs.get('session').config.get('safe_mode')):29 try:30 return function(method, url, **kwargs)30 except (RequestException, ConnectionError, HTTPError) as e:31 except (RequestException, ConnectionError, HTTPError, socket.timeout) as e:32 r = Response()33 r.error = e34 r.raw = HTTPResponse() # otherwise, tests fail35 r.status_code = 0 # with this status_code, content returns None
3 unmodified lines