Catch ReadTimeout exception on requests

This commit is contained in:
micbou 2016-03-05 22:13:32 +01:00
parent d4f8c1d404
commit f6d5f68d6b
4 changed files with 14 additions and 5 deletions

View File

@ -23,11 +23,12 @@ from future import standard_library
standard_library.install_aliases() standard_library.install_aliases()
from builtins import * # noqa from builtins import * # noqa
from requests.exceptions import ReadTimeout
import vim import vim
from ycmd.responses import ServerError from ycmd.responses import ServerError
from ycm.client.base_request import ( BaseRequest, BuildRequestData, from ycm.client.base_request import ( BaseRequest, BuildRequestData,
HandleServerException ) HandleServerException )
from ycm import vimsupport from ycm import vimsupport
from ycmd.utils import ToUnicode from ycmd.utils import ToUnicode
@ -56,7 +57,7 @@ class CommandRequest( BaseRequest ):
try: try:
self._response = self.PostDataToHandler( request_data, self._response = self.PostDataToHandler( request_data,
'run_completer_command' ) 'run_completer_command' )
except ServerError as e: except ( ServerError, ReadTimeout ) as e:
HandleServerException( e ) HandleServerException( e )

View File

@ -23,6 +23,8 @@ from future import standard_library
standard_library.install_aliases() standard_library.install_aliases()
from builtins import * # noqa from builtins import * # noqa
from requests.exceptions import ReadTimeout
from ycm.client.base_request import ( BaseRequest, BuildRequestData, from ycm.client.base_request import ( BaseRequest, BuildRequestData,
HandleServerException ) HandleServerException )
from ycmd.responses import ServerError from ycmd.responses import ServerError
@ -40,7 +42,7 @@ class CompleterAvailableRequest( BaseRequest ):
try: try:
self._response = self.PostDataToHandler( request_data, self._response = self.PostDataToHandler( request_data,
'semantic_completion_available' ) 'semantic_completion_available' )
except ServerError as e: except ( ServerError, ReadTimeout ) as e:
HandleServerException( e ) HandleServerException( e )

View File

@ -23,6 +23,8 @@ from future import standard_library
standard_library.install_aliases() standard_library.install_aliases()
from builtins import * # noqa from builtins import * # noqa
from requests.exceptions import ReadTimeout
from ycmd.utils import ToUnicode from ycmd.utils import ToUnicode
from ycm.client.base_request import ( BaseRequest, JsonFromFuture, from ycm.client.base_request import ( BaseRequest, JsonFromFuture,
HandleServerException, HandleServerException,
@ -59,7 +61,7 @@ class CompletionRequest( BaseRequest ):
HandleServerException( MakeServerException( e ) ) HandleServerException( MakeServerException( e ) )
return JsonFromFuture( self._response_future )[ 'completions' ] return JsonFromFuture( self._response_future )[ 'completions' ]
except ServerError as e: except ( ServerError, ReadTimeout ) as e:
HandleServerException( e ) HandleServerException( e )
return [] return []

View File

@ -23,6 +23,8 @@ from future import standard_library
standard_library.install_aliases() standard_library.install_aliases()
from builtins import * # noqa from builtins import * # noqa
from requests.exceptions import ReadTimeout
from ycm import vimsupport from ycm import vimsupport
from ycmd.responses import UnknownExtraConf, ServerError from ycmd.responses import UnknownExtraConf, ServerError
from ycm.client.base_request import ( BaseRequest, BuildRequestData, from ycm.client.base_request import ( BaseRequest, BuildRequestData,
@ -66,7 +68,7 @@ class EventNotification( BaseRequest ):
_LoadExtraConfFile( e.extra_conf_file ) _LoadExtraConfFile( e.extra_conf_file )
else: else:
_IgnoreExtraConfFile( e.extra_conf_file ) _IgnoreExtraConfFile( e.extra_conf_file )
except ServerError as e: except ( ServerError, ReadTimeout ) as e:
HandleServerException( e ) HandleServerException( e )
return self._cached_response if self._cached_response else [] return self._cached_response if self._cached_response else []
@ -76,10 +78,12 @@ def SendEventNotificationAsync( event_name, extra_data = None ):
event = EventNotification( event_name, extra_data ) event = EventNotification( event_name, extra_data )
event.Start() event.Start()
def _LoadExtraConfFile( filepath ): def _LoadExtraConfFile( filepath ):
BaseRequest.PostDataToHandler( { 'filepath': filepath }, BaseRequest.PostDataToHandler( { 'filepath': filepath },
'load_extra_conf_file' ) 'load_extra_conf_file' )
def _IgnoreExtraConfFile( filepath ): def _IgnoreExtraConfFile( filepath ):
BaseRequest.PostDataToHandler( { 'filepath': filepath }, BaseRequest.PostDataToHandler( { 'filepath': filepath },
'ignore_extra_conf_file' ) 'ignore_extra_conf_file' )