🚸 Show specific error on upload failure

Closes #4367
This commit is contained in:
Gina Häußge committed 2022-01-24 12:12:04 +01:00
1 parent 797e3454cd
commit 19072b4b33
2 files changed
+37 -12

No files matched your search

+2 -3
View File
@@ -575,7 +575,7 @@ def uploadGcodeFile(target):
futureFilename = None
if futureFilename is None:
abort(415, description="Can not upload file, wrong format?")
abort(400, description="Can not upload file, invalid file name")
# prohibit overwriting currently selected file while it's being printed
futureFullPath = fileManager.join_path(
@@ -652,11 +652,10 @@ def uploadGcodeFile(target):
)
except octoprint.filemanager.storage.StorageError as e:
if e.code == octoprint.filemanager.storage.StorageError.INVALID_FILE:
abort(400, description="Could not upload file, invalid type")
abort(415, description="Could not upload file, invalid type")
else:
abort(500, description="Could not upload file")
if octoprint.filemanager.valid_file_type(added_file, "stl"):
filename = added_file
done = True
else:
@@ -1689,15 +1689,41 @@ $(function () {
return extension.toLowerCase();
}).sort();
extensions = extensions.join(", ");
var error =
"<p>" +
_.sprintf(
gettext(
"Could not upload the file. Make sure that it is a readable, valid file with one of these extensions: %(extensions)s"
),
{extensions: _.escape(extensions)}
) +
"</p>";
var error = "<p>";
switch (data.jqXHR.status) {
case 409:
// already printing or otherwise busy
if (e.target.id === "gcode_upload_sd") {
error += gettext(
"Could not upload the file to the printer's SD. Make sure the SD is initialized and the printer is not busy with a print already."
);
} else {
error += gettext(
"Could not upload the file, overwrite not possible. Make sure it is not already printing and that you have allowed overwriting."
);
}
break;
case 415:
// unknown file type
error += _.sprintf(
gettext(
"Could not upload the file. Make sure that it is a readable, valid file with one of these extensions: %(extensions)s"
),
{extensions: _.escape(extensions)}
);
break;
default:
// any other kind of error
error += gettext(
"Could not upload the file. Please check octoprint.log for possible reasons."
);
break;
}
error += "</p>";
if (data.jqXHR.responseText) {
error += pnotifyAdditionalInfo(
"<pre>" + _.escape(data.jqXHR.responseText) + "</pre>"