From 790be86f134ddb15cc9e701333028b94cdf59fc4 Mon Sep 17 00:00:00 2001 From: MOIS3Y Date: Thu, 31 Aug 2023 13:34:40 +0900 Subject: [PATCH] Fix: ajax upload error message and increase the request timeout --- .../static/collector/js/jq.upload.progress.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/logs_collector/collector/static/collector/js/jq.upload.progress.js b/logs_collector/collector/static/collector/js/jq.upload.progress.js index eea0bd8..c4e3a21 100644 --- a/logs_collector/collector/static/collector/js/jq.upload.progress.js +++ b/logs_collector/collector/static/collector/js/jq.upload.progress.js @@ -20,6 +20,7 @@ $(function () { dataType: 'json', xhr:function(){ const xhr = new window.XMLHttpRequest(); + xhr.timeout = 3600000; // increase request timeout to 1 hour xhr.upload.addEventListener('progress', e=>{ if(e.lengthComputable){ const percentProgress = (e.loaded/e.total)*100; @@ -51,17 +52,17 @@ $(function () { uploadForm.reset() progress_bar.classList.add('not-visible') }, - error: function(data, textStatus, jqXHR){ - console.log(data.responseJSON.error); + error: function(jqXHR, textStatus, errorThrown){ + console.log(jqXHR); let type = "danger"; let error_message = "Unexpected error. Try again please" - if (data.status === 423) { - error_message = `Error ${data.status}: ${data.responseJSON.error}` + if (jqXHR.status === 423) { + error_message = `Error ${jqXHR.status}: ${jqXHR.responseJSON.error}` } - if (data.status === 403) { - error_message = `Error ${data.status}: ${data.responseJSON.error}` + if (jqXHR.status === 403) { + error_message = `Error ${jqXHR.status}: ${jqXHR.responseJSON.error}` } - if (data.status === 401) { + if (jqXHR.status === 401) { error_message = 'The token field cannot be empty' } alert_container.innerHTML = [