Always provide error message if upload failed

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

View file

@ -63,7 +63,9 @@ class UploadMaterialsJob(Job):
def onUploadRequestCompleted(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]): def onUploadRequestCompleted(self, reply: "QNetworkReply", error: Optional["QNetworkReply.NetworkError"]):
if error is not None: if error is not None:
Logger.error(f"Could not request URL to upload material archive to: {error}") Logger.error(f"Could not request URL to upload material archive to: {error}")
self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
self.uploadCompleted.emit(self.getResult(), self.getError())
return return
response_data = HttpRequestManager.readJSON(reply) response_data = HttpRequestManager.readJSON(reply)
@ -71,16 +73,19 @@ class UploadMaterialsJob(Job):
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.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)
self.uploadCompleted.emit(self.getResult(), self.getError())
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.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)
self.uploadCompleted.emit(self.getResult(), self.getError())
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.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)
self.uploadCompleted.emit(self.getResult(), self.getError())
return return
upload_url = response_data["upload_url"] upload_url = response_data["upload_url"]
@ -100,6 +105,10 @@ class UploadMaterialsJob(Job):
Logger.error(f"Failed to upload material archive: {error}") Logger.error(f"Failed to upload material archive: {error}")
self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory."))) self.setError(UploadMaterialsError(catalog.i18nc("@text:error", "Failed to connect to Digital Factory.")))
self.setResult(self.Result.FAILED) self.setResult(self.Result.FAILED)
return
else: else:
self.setResult(self.Result.SUCCESS) self.setResult(self.Result.SUCCESS)
self.uploadCompleted.emit(self.getResult(), self.getError()) self.uploadCompleted.emit(self.getResult(), self.getError())