Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Base class for all Eva errors"""
class EvaValidationError(EvaError, ValueError):
"""Error thrown when the request arguements are invalid"""
class EvaAuthError(EvaError, Exception):
"""Error thrown when request requires authentication"""
class EvaAdminError(EvaError, Exception):
"""Error thrown when request requires admin user rights"""
class EvaServerError(EvaError, Exception):
"""Error thrown when Eva returns an internal server error"""
class EvaDisconnectionError(EvaError, Exception):
"""Error thrown when Eva websocket connection is closed"""
class EvaLockError(EvaError, Exception):
"""Error thrown when Eva has robot lock issues"""
class EvaAutoRenewError(EvaError, Exception):
"""Error thrown when automatic session renewal fails but not the original request"""
def eva_error(label, r=None):
error_string += ' with error [{}]'.format(r_json)
except ValueError:
pass
if r.status_code == 401:
raise EvaValidationError(error_string)
elif r.status_code == 401:
raise EvaAuthError(error_string)
elif r.status_code == 403:
raise EvaAdminError(error_string)
elif 400 <= r.status_code < 500:
raise EvaError(error_string)
elif 500 <= r.status_code < 600:
raise EvaServerError(error_string)
else:
raise EvaError(error_string)
class EvaError(Exception):
"""Base class for all Eva errors"""
class EvaValidationError(EvaError, ValueError):
"""Error thrown when the request arguements are invalid"""
class EvaAuthError(EvaError, Exception):
"""Error thrown when request requires authentication"""
class EvaAdminError(EvaError, Exception):
"""Error thrown when request requires admin user rights"""
class EvaServerError(EvaError, Exception):
"""Error thrown when Eva returns an internal server error"""
class EvaDisconnectionError(EvaError, Exception):
"""Error thrown when Eva websocket connection is closed"""
class EvaLockError(EvaError, Exception):
def eva_error(label, r=None):
if r is not None:
__handle_http_error(label, r)
else:
raise EvaError(label)
"""Error thrown when request requires admin user rights"""
class EvaServerError(EvaError, Exception):
"""Error thrown when Eva returns an internal server error"""
class EvaDisconnectionError(EvaError, Exception):
"""Error thrown when Eva websocket connection is closed"""
class EvaLockError(EvaError, Exception):
"""Error thrown when Eva has robot lock issues"""
class EvaAutoRenewError(EvaError, Exception):
"""Error thrown when automatic session renewal fails but not the original request"""
def eva_error(label, r=None):
if r is not None:
__handle_http_error(label, r)
else:
raise EvaError(label)
def __handle_http_error(label, r):
error_string = '{}: status code {}'.format(label, r.status_code)
try:
r_json = r.json()
if 'error' in r_json:
error_string += ' with error [{}]'.format(r_json)
class EvaError(Exception):
"""Base class for all Eva errors"""
class EvaValidationError(EvaError, ValueError):
"""Error thrown when the request arguements are invalid"""
class EvaAuthError(EvaError, Exception):
"""Error thrown when request requires authentication"""
class EvaAdminError(EvaError, Exception):
"""Error thrown when request requires admin user rights"""
class EvaServerError(EvaError, Exception):
"""Error thrown when Eva returns an internal server error"""
class EvaDisconnectionError(EvaError, Exception):
"""Error thrown when Eva websocket connection is closed"""
class EvaLockError(EvaError, Exception):
"""Error thrown when Eva has robot lock issues"""
class EvaAutoRenewError(EvaError, Exception):
def lock_wait_for(self, interval_sec=2, timeout=None):
if self.lock_status()['owner'] == 'you':
return
if timeout is not None:
timeoutT = time.time() + timeout
while True:
try:
self.lock_lock()
return
except Exception as e:
if not isinstance(e, EvaError):
raise e
pass
if timeout is not None:
if timeoutT < time.time():
eva_error('lock_wait_for timeout triggered')
time.sleep(interval_sec)
def api_call_with_auth(self, *args, **kwargs):
r = self.__api_request(*args, **kwargs)
# Try creating a new session if we get an auth error and retrying the failed request
if r.status_code == 401:
self.__logger.debug('Creating a new session and retrying failed request')
self.auth_create_session()
return self.__api_request(*args, **kwargs)
if self.renew_period < time.time() - self.__last_renew < 30 * 60:
self.__logger.debug('Automatically renewing session')
try:
self.auth_renew_session()
except EvaError as e:
raise EvaAutoRenewError('Failed to automatically renew, got error {}'.format(str(e)))
return r
class EvaError(Exception):
"""Base class for all Eva errors"""
class EvaValidationError(EvaError, ValueError):
"""Error thrown when the request arguements are invalid"""
class EvaAuthError(EvaError, Exception):
"""Error thrown when request requires authentication"""
class EvaAdminError(EvaError, Exception):
"""Error thrown when request requires admin user rights"""
class EvaServerError(EvaError, Exception):
"""Error thrown when Eva returns an internal server error"""
class EvaDisconnectionError(EvaError, Exception):