def ensure_notifications_thread(self): """Ensure notification thread is running""" if not self.has_active_notification_thread: if self.config.get('autostart_notification_thread'): self.start_notifications() else: raise CloudUnhandledError( "notifications thread required for this API call")
def value(self): """Get the value of the finished async request, if it is available. :raises CloudUnhandledError: When not checking value of `error` or `is_done` first :return: the payload value :rtype: str """ if self.error: raise CloudUnhandledError("Async request returned an error. Need to check for errors," "before getting value.\nError: %s" % self.error) return self.db[self.async_id]["payload"]
def value(self): """Get the value of the finished async request, if it is available. :raises CloudUnhandledError: When not checking value of `error` or `is_done` first :return: the payload value :rtype: str """ status_code, error_msg, payload = self.check_error() if not self._status_ok(status_code) and not payload: raise CloudUnhandledError( "Attempted to decode async request which returned an error.", reason=error_msg, status=status_code) return self.db[self.async_id]["payload"]
def check_error(self): """Check if the async response is an error. Take care to call `is_done` before calling `error`. Note that the error messages are always encoded as strings. :raises CloudUnhandledError: When not checking `is_done` first :return: status_code, error_msg, payload :rtype: tuple """ if not self.is_done: raise CloudUnhandledError( "Need to check if request is done, before checking for error") response = self.db[self.async_id] error_msg = response["error"] status_code = int(response["status_code"]) payload = response["payload"] return status_code, error_msg, payload
def error(self): """Check if the async response is an error. Take care to call `is_done` before calling `error`. Note that the error messages are always encoded as strings. :raises CloudUnhandledError: When not checking `is_done` first :return: the error value/payload, if found. :rtype: str """ if not self.is_done: raise CloudUnhandledError("Need to check if request is done, before checking for error") response = self.db[self.async_id] error_msg = response["error"] status_code = int(response["status_code"]) payload = response["payload"] if status_code != 200 and not error_msg and not payload: return "Async error (%s). Status code: %r" % (self.async_id, status_code) return error_msg