diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index 8106d4497..eb480f215 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -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: diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 10d268c70..9fe1bc066 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -1689,15 +1689,41 @@ $(function () { return extension.toLowerCase(); }).sort(); extensions = extensions.join(", "); - var 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)} - ) + - "

"; + + var error = "

"; + 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 += "

"; + if (data.jqXHR.responseText) { error += pnotifyAdditionalInfo( "
" + _.escape(data.jqXHR.responseText) + "
"