From b686da5e561976838924d55b4cc97495a1ad5d6c Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Wed, 22 Jan 2025 19:54:56 +0100 Subject: [PATCH] WebClient: improve error message after the session expires Signed-off-by: Nicola Murino --- static/locales/en/translation.json | 3 +- static/locales/it/translation.json | 3 +- templates/webclient/files.html | 52 +++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/static/locales/en/translation.json b/static/locales/en/translation.json index 04b246f1..e67496b5 100644 --- a/static/locales/en/translation.json +++ b/static/locales/en/translation.json @@ -273,7 +273,8 @@ "thursday": "Thursday", "friday": "Friday", "saturday": "Saturday", - "sunday": "Sunday" + "sunday": "Sunday", + "expired_session": "Your session has expired. Please log in again" }, "fs": { "view_file": "View file \"{{- path}}\"", diff --git a/static/locales/it/translation.json b/static/locales/it/translation.json index 1ccf9407..38379f93 100644 --- a/static/locales/it/translation.json +++ b/static/locales/it/translation.json @@ -273,7 +273,8 @@ "thursday": "Giovedì", "friday": "Venerdì", "saturday": "Sabato", - "sunday": "Domenica" + "sunday": "Domenica", + "expired_session": "La tua sessione è scaduta. Effettua nuovamente l'accesso" }, "fs": { "view_file": "Visualizza file \"{{- path}}\"", diff --git a/templates/webclient/files.html b/templates/webclient/files.html index dcd058d1..e280f5dd 100644 --- a/templates/webclient/files.html +++ b/templates/webclient/files.html @@ -349,6 +349,8 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). if (json.message) { txt = json.message; } + } else { + txt = "general.expired_session"; } } if (!txt){ @@ -500,6 +502,8 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). let errorMessage = ""; if (error && error.response) { switch (error.response.status) { + case 200: + errorMessage = "general.expired_session"; case 403: errorMessage = "fs.create_dir.err_403"; break; @@ -1477,8 +1481,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). }).then((result)=>{ if (result.error) { hasError = true; + let message = "fs.copy.err_generic"; + if (result.is_redirect){ + message = "general.expired_session"; + } ModalAlert.fire({ - text: $.t("fs.copy.err_generic"), + text: $.t(message), icon: "warning", confirmButtonText: $.t('general.ok'), customClass: { @@ -1626,14 +1634,18 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). }).then((result)=>{ if (result.error) { hasError = true; - ModalAlert.fire({ - text: $.t("fs.move.err_generic"), - icon: "warning", - confirmButtonText: $.t('general.ok'), - customClass: { - confirmButton: "btn btn-primary" + let message = "fs.move.err_generic"; + if (result.is_redirect){ + message = "general.expired_session"; } - }); + ModalAlert.fire({ + text: $.t(message), + icon: "warning", + confirmButtonText: $.t('general.ok'), + customClass: { + confirmButton: "btn btn-primary" + } + }); } else if (result.data.length > 0){ hasError = true; ModalAlert.fire({ @@ -1653,6 +1665,9 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). KTApp.hidePageLoading(); let errorMessage; switch (status) { + case 405: + errorMessage = "general.expired_session"; + break; case 403: errorMessage = "fs.delete.err_403"; break; @@ -1860,8 +1875,12 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). }).then((result)=>{ if (result.error) { KTApp.hidePageLoading(); + let message = $.t('fs.rename.err_generic', { name: oldName }); + if (result.is_redirect){ + message = $.t('general.expired_session'); + } ModalAlert.fire({ - text: $.t('fs.rename.err_generic', { name: oldName }), + text: message, icon: "warning", confirmButtonText: $.t('general.ok'), customClass: { @@ -1951,6 +1970,8 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). let errorMessage = ""; if (error && error.response) { switch (error.response.status) { + case 200: + errorMessage = "general.expired_session"; case 403: errorMessage = "fs.create_dir.err_403"; break; @@ -2100,7 +2121,11 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). }).then((result)=> { if (result.error) { has_errors = true; - setI18NData($('#errorTxt'), "fs.upload.err_generic"); + let message = "fs.upload.err_generic"; + if (result.is_redirect){ + message = "general.expired_session"; + } + setI18NData($('#errorTxt'), message); $('#errorMsg').removeClass("d-none"); uploadFile(); return; @@ -2163,13 +2188,16 @@ explicit grant from the SFTPGo Team (support@sftpgo.com). return status == 200; } }).then(function(response){ + let isJsonResponse = response.headers['content-type'] === 'application/json' promiseResolve({ - error: false, + error: !isJsonResponse, + is_redirect: !isJsonResponse, data: response.data }); }).catch(function(error){ promiseResolve({ - error: true + error: true, + is_redirect: false }); }); }