* [pve-devel] [PATCH manager] ui: upload: catch non-json responses
@ 2025-07-11 10:04 Dominik Csapak
0 siblings, 0 replies; only message in thread
From: Dominik Csapak @ 2025-07-11 10:04 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-07-11 10:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-11 10:04 [pve-devel] [PATCH manager] ui: upload: catch non-json responses Dominik Csapak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox