def wrapped(*args, **kwargs): if client() is not None: try: return func(*args, **kwargs) except ConnectionError as e: raise exceptions.SearchUnavailableError(str(e)) except NotFoundError as e: raise exceptions.IndexNotFoundError(e.error) except RequestError as e: if e.error == 'search_phase_execution_exception': raise exceptions.MalformedQueryError( 'Failed to parse query') if 'ParseException' in e.error: # ES 1.5 raise exceptions.MalformedQueryError(e.error) if type(e.error) == dict: # ES 2.0 try: root_cause = e.error['root_cause'][0] if root_cause['type'] == 'query_parsing_exception': raise exceptions.MalformedQueryError( root_cause['reason']) except (AttributeError, KeyError): pass raise exceptions.SearchException(e.error) except TransportError as e: # Catch and wrap generic uncaught ES error codes. TODO: Improve fix for https://openscience.atlassian.net/browse/OSF-4538 raise exceptions.SearchException(e.error) sentry.log_message( 'Elastic search action failed. Is elasticsearch running?') raise exceptions.SearchUnavailableError( 'Failed to connect to elasticsearch')
def wrapped(*args, **kwargs): if es is not None: try: return func(*args, **kwargs) except ConnectionError: raise exceptions.SearchUnavailableError('Could not connect to elasticsearch') except NotFoundError as e: raise exceptions.IndexNotFoundError(e.error) except RequestError as e: if 'ParseException' in e.error: raise exceptions.MalformedQueryError(e.error) raise exceptions.SearchException(e.error) except TransportError as e: # Catch and wrap generic uncaught ES error codes. TODO: Improve fix for https://openscience.atlassian.net/browse/OSF-4538 raise exceptions.SearchException(e.error) sentry.log_message('Elastic search action failed. Is elasticsearch running?') raise exceptions.SearchUnavailableError("Failed to connect to elasticsearch")
def wrapped(*args, **kwargs): if es is not None: try: return func(*args, **kwargs) except ConnectionError: raise exceptions.SearchUnavailableError('Could not connect to elasticsearch') except NotFoundError as e: raise exceptions.IndexNotFoundError(e.error) except RequestError as e: if 'ParseException' in e.error: raise exceptions.MalformedQueryError(e.error) raise exceptions.SearchException(e.error) sentry.log_message('Elastic search action failed. Is elasticsearch running?') raise exceptions.SearchUnavailableError("Failed to connect to elasticsearch")