Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)