[pve-devel] [PATCH manager] ui: upload: catch non-json responses

Dominik Csapak d.csapak at proxmox.com
Fri Jul 11 12:04:42 CEST 2025


when the responseText contains a plain message instead of JSON, the code
would throw an exception here that we don't catch and not show an error,
but also not progressing with the upload.

Catch the error, and show the originally generated message if
responseText is not valid JSON.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
While testing upload errors to see if we can get a better error message
than 'Error 0 occurred', i noticed that in chrome we fail here to show
the valid error message.

Note that this does not improve the 'Error 0' message, only cases where
the browser fails on a different path.

 www/manager6/window/UploadToStorage.js | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/www/manager6/window/UploadToStorage.js b/www/manager6/window/UploadToStorage.js
index cc53596d..96d8dabf 100644
--- a/www/manager6/window/UploadToStorage.js
+++ b/www/manager6/window/UploadToStorage.js
@@ -115,9 +115,14 @@ Ext.define('PVE.window.UploadToStorage', {
                     const err = Ext.htmlEncode(xhr.statusText);
                     let msg = `${gettext('Error')} ${xhr.status.toString()}: ${err}`;
                     if (xhr.responseText !== '') {
-                        const result = Ext.decode(xhr.responseText);
-                        result.message = msg;
-                        msg = Proxmox.Utils.extractRequestError(result, true);
+                        try {
+                            const result = Ext.decode(xhr.responseText);
+                            result.message = msg;
+                            msg = Proxmox.Utils.extractRequestError(result, true);
+                        } catch (_e) {
+                            // we could not decode the responseText, so it's
+                            // probably not json, so show initial error message
+                        }
                     }
                     Ext.Msg.alert(gettext('Error'), msg, (btn) => view.close());
                 },
-- 
2.39.5





More information about the pve-devel mailing list