diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index 63c11ba484..9314e067a2 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -3,10 +3,11 @@ from time import time import os -from typing import List, Optional, cast +from typing import cast, List, Optional, TYPE_CHECKING from PyQt5.QtCore import QObject, QUrl, pyqtProperty, pyqtSignal, pyqtSlot from PyQt5.QtGui import QDesktopServices +from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest # Parse errors specific to print job uploading. from UM import i18nCatalog from UM.Backend.Backend import BackendState @@ -23,6 +24,7 @@ from ..ExportFileJob import ExportFileJob from ..UltimakerNetworkedPrinterOutputDevice import UltimakerNetworkedPrinterOutputDevice from ..Messages.PrintJobUploadBlockedMessage import PrintJobUploadBlockedMessage from ..Messages.PrintJobUploadErrorMessage import PrintJobUploadErrorMessage +from ..Messages.PrintJobUploadQueueFullMessage import PrintJobUploadQueueFullMessage from ..Messages.PrintJobUploadSuccessMessage import PrintJobUploadSuccessMessage from ..Models.Http.CloudClusterResponse import CloudClusterResponse from ..Models.Http.CloudClusterStatus import CloudClusterStatus @@ -194,7 +196,7 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): # The mesh didn't change, let's not upload it to the cloud again. # Note that self.writeFinished is called in _onPrintUploadCompleted as well. if self._uploaded_print_job: - self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintUploadCompleted) + self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintUploadCompleted, self._onPrintUploadSpecificError) return # Export the scene to the correct file type. @@ -240,7 +242,7 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): if not print_job: # It's possible that another print job is requested in the meanwhile, which then fails to upload with an error, which sets self._uploaded_print_job to `None`. # TODO: Maybe _onUploadError shouldn't set the _uploaded_print_job to None or we need to prevent such asynchronous cases. return # Prevent a crash. - self._api.requestPrint(self.key, print_job.job_id, self._onPrintUploadCompleted) + self._api.requestPrint(self.key, print_job.job_id, self._onPrintUploadCompleted, self._onPrintUploadSpecificError) def _onPrintUploadCompleted(self, response: CloudPrintResponse) -> None: """Shows a message when the upload has succeeded @@ -251,9 +253,23 @@ class CloudOutputDevice(UltimakerNetworkedPrinterOutputDevice): PrintJobUploadSuccessMessage().show() self.writeFinished.emit() - def _onUploadError(self, message: str = None) -> None: - """Displays the given message if uploading the mesh has failed + def _onPrintUploadSpecificError(self, reply: "QNetworkReply", _: "QNetworkReply.NetworkError"): + """ + Displays a message when an error occurs specific to uploading print job (i.e. queue is full). + """ + error_code = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) + if error_code == 409: + PrintJobUploadQueueFullMessage().show() + else: + PrintJobUploadErrorMessage(I18N_CATALOG.i18nc("@error:send", "Unknown error code when uploading print job: {0}", error_code)).show() + self._progress.hide() + self._uploaded_print_job = None + self.writeError.emit() + + def _onUploadError(self, message: str = None) -> None: + """ + Displays the given message if uploading the mesh has failed due to a generic error (i.e. lost connection). :param message: The message to display. """ self._progress.hide()