The exception handling appears to be routing generic exceptions (i.e. Exception) through custom exceptions (i.e. ApiError) however in doing so it is passing response which may have failed to assign.
Take the following example:
try:
response = self._session.post(uri, json=data, headers=headers)
# Validate the response
self._check_response_code(response, DEFAULT_SUCCESS_RESPONSE_CODES)
self._print_debug_response(response)
except Exception:
> raise ApiError(response)
E UnboundLocalError: local variable 'response' referenced before assignment
In this case if self._session.post excepts, then response will not be assigned and we do not get proper exception handling. There are a few different approaches that can be taken here (one of which would be to initialize response to None and then handle this accordingly).
The exception handling appears to be routing generic exceptions (i.e.
Exception) through custom exceptions (i.e.ApiError) however in doing so it is passingresponsewhich may have failed to assign.Take the following example:
In this case if
self._session.postexcepts, thenresponsewill not be assigned and we do not get proper exception handling. There are a few different approaches that can be taken here (one of which would be to initialize response to None and then handle this accordingly).