public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] ui: upload: catch non-json responses
Date: Fri, 11 Jul 2025 12:04:42 +0200	[thread overview]
Message-ID: <20250711100442.2472847-1-d.csapak@proxmox.com> (raw)

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@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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


                 reply	other threads:[~2025-07-11 10:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250711100442.2472847-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal