Always provide error message if upload failed

Contributes to issue CURA-8609.
This commit is contained in:
Ghostkeeper 2021-10-12 13:16:28 +02:00
parent 4ccd4caaad
commit a6b6b075ea
No known key found for this signature in database
GPG key ID: 68F39EA88EEED5FF

View file

@ -9,12 +9,15 @@ import enum
import cura.CuraApplication # Imported like this to prevent circular imports. import cura.CuraApplication # Imported like this to prevent circular imports.
from cura.UltimakerCloud import UltimakerCloudConstants # To know where the API is. from cura.UltimakerCloud import UltimakerCloudConstants # To know where the API is.
from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To know how to communicate with this server. from cura.UltimakerCloud.UltimakerCloudScope import UltimakerCloudScope # To know how to communicate with this server.
from UM.i18n import i18nCatalog
from UM.Job import Job from UM.Job import Job
from UM.Logger import Logger from UM.Logger import Logger
from UM.Signal import Signal from UM.Signal import Signal
from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To call the API. from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To call the API.
from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope
catalog = i18nCatalog("cura")
from typing import Optional, TYPE_CHECKING from typing import Optional, TYPE_CHECKING
if TYPE_CHECKING: if TYPE_CHECKING:
from PyQt5.QtNetwork import QNetworkReply from PyQt5.QtNetwork import QNetworkReply
@ -66,14 +69,17 @@ class UploadMaterialsJob(Job):
response_data = HttpRequestManager.readJSON(reply) response_data = HttpRequestManager.readJSON(reply)
if response_data is None: if response_data is None:
Logger.error(f"Invalid response to material upload request. Could not parse JSON data.") Logger.error(f"Invalid response to material upload request. Could not parse JSON data.")
self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "The response from Digital Factory appears to be corrupted.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
return return
if "upload_url" not in response_data: if "upload_url" not in response_data:
Logger.error(f"Invalid response to material upload request: Missing 'upload_url' field to upload archive to.") Logger.error(f"Invalid response to material upload request: Missing 'upload_url' field to upload archive to.")
self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "The response from Digital Factory is missing important information.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
return return
if "material_profile_id" not in response_data: if "material_profile_id" not in response_data:
Logger.error(f"Invalid response to material upload request: Missing 'material_profile_id' to communicate about the materials with the server.") Logger.error(f"Invalid response to material upload request: Missing 'material_profile_id' to communicate about the materials with the server.")
self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "The response from Digital Factory is missing important information.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
return return
@ -92,7 +98,7 @@ class UploadMaterialsJob(Job):
def onUploadCompleted(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]): def onUploadCompleted(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]):
if error is not None: if error is not None:
Logger.error(f"Failed to upload material archive: {error}") Logger.error(f"Failed to upload material archive: {error}")
self.setError(UploadMaterialsError(error)) self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
else: else:
self.setResult(self.Result.SUCCESS) self.setResult(self.Result.SUCCESS)
@ -101,7 +107,7 @@ class UploadMaterialsJob(Job):
def onError(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]): def onError(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]):
Logger.error(f"Failed to upload material archive: {error}") Logger.error(f"Failed to upload material archive: {error}")
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
self.setError(UploadMaterialsError(error)) self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory.")))
self.uploadCompleted.emit(self.getResult(), self.getError()) self.uploadCompleted.emit(self.getResult(), self.getError())
class UploadMaterialsError(Exception): class UploadMaterialsError(Exception):