From 1d1b0e58d2cd1998cb2f81c4e35f513402c3879e Mon Sep 17 00:00:00 2001 From: Andrew Bauer Date: Sun, 20 Sep 2020 08:41:16 -0500 Subject: [PATCH] consolidate getJson fail callbacks to one function --- web/skins/classic/js/skin.js | 32 +++++++++------------------ web/skins/classic/views/js/console.js | 10 ++------- web/skins/classic/views/js/event.js | 5 +---- web/skins/classic/views/js/events.js | 30 +++++-------------------- web/skins/classic/views/js/export.js | 5 +---- web/skins/classic/views/js/filter.js | 5 +---- web/skins/classic/views/js/frames.js | 5 +---- web/skins/classic/views/js/options.js | 10 ++------- 8 files changed, 25 insertions(+), 77 deletions(-) diff --git a/web/skins/classic/js/skin.js b/web/skins/classic/js/skin.js index 578b7f9d4..bab7f78b6 100644 --- a/web/skins/classic/js/skin.js +++ b/web/skins/classic/js/skin.js @@ -393,10 +393,7 @@ if ( currentView != 'none' && currentView != 'login' ) { $j(".optionhelp").click(function(evt) { $j.getJSON(thisUrl + '?request=modal&modal=optionhelp&ohndx=' + evt.target.id) .done(optionhelpModal) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); }); }); @@ -420,7 +417,7 @@ if ( currentView != 'none' && currentView != 'login' ) { .done(setNavBar) .fail(function(jqxhr, textStatus, error) { console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); + console.log("Response Text: " + jqxhr.responseText.replace(/(<([^>]+)>)/gi, '')); if ( textStatus != "timeout" ) { // The idea is that this should only fail due to auth, so reload the page // which should go to login if it can't stay logged in. @@ -722,10 +719,7 @@ function reminderClickFunction() { var option = $j(this).data('pdsa-dropdown-val'); $j.getJSON(thisUrl + '?view=version&action=version&option=' + option) .done(window.location.reload(true)) //Do a full refresh to update ZM_DYN_LAST_VERSION - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); }); } @@ -745,10 +739,7 @@ function enoperm() { $j('#ENoPerm').modal('hide'); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function getLogoutModal() { @@ -760,10 +751,7 @@ function getLogoutModal() { $j("body").append(data.html); } }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function getStateModal() { @@ -777,10 +765,7 @@ function getStateModal() { $j('#modalState').modal('show'); manageStateModalBtns(); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function manageStateModalBtns() { @@ -845,3 +830,8 @@ function stateStuff(action, runState, newState) { location.reload(); }); } + +function logAjaxFail(jqxhr, textStatus, error) { + console.log("Request Failed: " + textStatus + ", " + error); + console.log("Response Text: " + jqxhr.responseText.replace(/(<([^>]+)>)/gi, '')); // strip any html from the response +} diff --git a/web/skins/classic/views/js/console.js b/web/skins/classic/views/js/console.js index 9085e11cc..47201689d 100644 --- a/web/skins/classic/views/js/console.js +++ b/web/skins/classic/views/js/console.js @@ -188,10 +188,7 @@ function initPage() { $j('#donateForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } // Makes table sortable @@ -217,10 +214,7 @@ function initPage() { // Manage the Function modal manageFunctionModal(); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function applySort(event, ui) { diff --git a/web/skins/classic/views/js/event.js b/web/skins/classic/views/js/event.js index 6781949d1..e20d460cf 100644 --- a/web/skins/classic/views/js/event.js +++ b/web/skins/classic/views/js/event.js @@ -50,10 +50,7 @@ var cueFrames = null; //make cueFrames available even if we don't send another a function initialAlarmCues(eventId) { $j.getJSON(thisUrl + '?view=request&request=status&entity=frames&id=' + eventId, setAlarmCues) //get frames data for alarmCues and inserts into html - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function setAlarmCues(data) { diff --git a/web/skins/classic/views/js/events.js b/web/skins/classic/views/js/events.js index 572fd6e29..04e03e43a 100644 --- a/web/skins/classic/views/js/events.js +++ b/web/skins/classic/views/js/events.js @@ -46,10 +46,7 @@ function getDelConfirmModal() { } manageDelConfirmModalBtns(); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } // Manage the DELETE CONFIRMATION modal button @@ -68,10 +65,7 @@ function manageDelConfirmModalBtns() { $j('#eventTable').bootstrapTable('refresh'); window.location.reload(true); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); }); // Manage the CANCEL modal button @@ -95,10 +89,7 @@ function getEventDetailModal(eid) { $j('#eventDetailForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function initPage() { @@ -199,10 +190,7 @@ function initPage() { $j('#eventTable').bootstrapTable('refresh'); window.location.reload(true); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); }); // Manage the UNARCHIVE button @@ -221,10 +209,7 @@ function initPage() { $j('#eventTable').bootstrapTable('refresh'); window.location.reload(true); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); if ( openFilterWindow ) { //opener.location.reload(true); @@ -259,10 +244,7 @@ function initPage() { $j('#eventDetailForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); }); // Manage the EXPORT button diff --git a/web/skins/classic/views/js/export.js b/web/skins/classic/views/js/export.js index e5c932122..dfe74ebe3 100644 --- a/web/skins/classic/views/js/export.js +++ b/web/skins/classic/views/js/export.js @@ -95,10 +95,7 @@ function getEventDetailModal(eid) { $j('#eventDetailForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function initPage() { diff --git a/web/skins/classic/views/js/filter.js b/web/skins/classic/views/js/filter.js index 993d66670..163a7fdde 100644 --- a/web/skins/classic/views/js/filter.js +++ b/web/skins/classic/views/js/filter.js @@ -422,10 +422,7 @@ function getModal(id) { } $j('#'+id+'Modal').modal('show'); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function manageModalBtns(id) { diff --git a/web/skins/classic/views/js/frames.js b/web/skins/classic/views/js/frames.js index a94e76c71..e78e16865 100644 --- a/web/skins/classic/views/js/frames.js +++ b/web/skins/classic/views/js/frames.js @@ -32,10 +32,7 @@ function detailFormatter(index, row, $detail) { .done(function(data) { $detail.html(data.html); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function initPage() { var backBtn = $j('#backBtn'); diff --git a/web/skins/classic/views/js/options.js b/web/skins/classic/views/js/options.js index 2629f33fe..843225a67 100644 --- a/web/skins/classic/views/js/options.js +++ b/web/skins/classic/views/js/options.js @@ -14,10 +14,7 @@ function getServerModal(sid) { $j('#serverModalForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function enableServerModal() { @@ -48,10 +45,7 @@ function getStorageModal(sid) { $j('#storageModalForm').submit(); }); }) - .fail(function(jqxhr, textStatus, error) { - console.log("Request Failed: " + textStatus + ", " + error); - console.log("Response Text: " + jqxhr.responseText); - }); + .fail(logAjaxFail); } function enableStorageModal() {