def _onUploadSlotCompleted(self, reply: QNetworkReply, error: Optional["QNetworkReply.NetworkError"] = None) -> None: if HttpRequestManager.safeHttpStatus(reply) >= 300: replyText = HttpRequestManager.readText(reply) Logger.warning("Could not request backup upload: %s", replyText) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE if HttpRequestManager.safeHttpStatus(reply) == 400: errors = json.loads(replyText)["errors"] if "moreThanMaximum" in [error["code"] for error in errors if error["meta"] and error["meta"]["field_name"] == "backup_size"]: self.backup_upload_error_message = catalog.i18nc("@error:file_size", "The backup exceeds the maximum file size.") self._job_done.set() return if error is not None: Logger.warning("Could not request backup upload: %s", HttpRequestManager.qt_network_error_name(error)) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE self._job_done.set() return backup_upload_url = HttpRequestManager.readJSON(reply)["data"]["upload_url"] # Upload the backup to storage. HttpRequestManager.getInstance().put( backup_upload_url, data=self._backup_zip, callback=self._uploadFinishedCallback, error_callback=self._uploadFinishedCallback )
def _onUploadSlotCompleted( self, reply: QNetworkReply, error: Optional["QNetworkReply.NetworkError"] = None) -> None: if error is not None: Logger.warning(str(error)) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE self._job_done.set() return if reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) >= 300: Logger.warning("Could not request backup upload: %s", HttpRequestManager.readText(reply)) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE self._job_done.set() return backup_upload_url = HttpRequestManager.readJSON( reply)["data"]["upload_url"] # Upload the backup to storage. HttpRequestManager.getInstance().put( backup_upload_url, data=self._backup_zip, callback=self._uploadFinishedCallback, error_callback=self._uploadFinishedCallback)
def _uploadFinishedCallback(self, reply: QNetworkReply, error: QNetworkReply.NetworkError = None): if not HttpRequestManager.replyIndicatesSuccess(reply, error): Logger.log("w", "Could not upload backup file: %s", HttpRequestManager.readText(reply)) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE self._job_done.set()
def _onUploadSlotCompleted( self, reply: QNetworkReply, error: Optional["QNetworkReply.NetworkError"] = None) -> None: if HttpRequestManager.safeHttpStatus(reply) >= 300: replyText = HttpRequestManager.readText(reply) Logger.warning("Could not request backup upload: %s", replyText) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE if HttpRequestManager.safeHttpStatus(reply) == 400: errors = json.loads(replyText)["errors"] if "moreThanMaximum" in [ error["code"] for error in errors if error["meta"] and error["meta"]["field_name"] == "backup_size" ]: if self._backup_zip is None: # will never happen; keep mypy happy zip_error = "backup is None." else: zip_error = "{} exceeds max size.".format( str(len(self._backup_zip))) sentry_sdk.capture_message( "backup failed: {}".format(zip_error), level="warning") self.backup_upload_error_message = catalog.i18nc( "@error:file_size", "The backup exceeds the maximum file size.") from sentry_sdk import capture_message self._job_done.set() return if error is not None: Logger.warning("Could not request backup upload: %s", HttpRequestManager.qt_network_error_name(error)) self.backup_upload_error_message = self.DEFAULT_UPLOAD_ERROR_MESSAGE self._job_done.set() return backup_upload_url = HttpRequestManager.readJSON( reply)["data"]["upload_url"] # Upload the backup to storage. HttpRequestManager.getInstance().put( backup_upload_url, data=self._backup_zip, callback=self._uploadFinishedCallback, error_callback=self._uploadFinishedCallback)