Skip to content

Commit 879de75

Browse files
gsthonzakral
authored andcommitted
Fixed a bare except
AFAIK the only exception which can occur here is one that the json.loads(..) could raise. So (TypeError or) ValueError. So except on that. and also log a warning in such case. bare excepts are 99.99% of the time simply bad/wrong. It's the case here.
1 parent 15e21e1 commit 879de75

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

elasticsearch/connection/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ def _raise_error(self, status_code, raw_data):
101101
error_message = additional_info.get('error', error_message)
102102
if isinstance(error_message, dict) and 'type' in error_message:
103103
error_message = error_message['type']
104-
except:
105-
# we don't care what went wrong
106-
pass
104+
except (ValueError, TypeError) as err:
105+
logger.warning('Undecodable raw error response from server: %s', err)
107106

108107
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
109108

0 commit comments

Comments
 (0)