From e2a6596cc21af3677b0e193dda77c7766ef0b9d6 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Thu, 3 Oct 2019 20:48:50 +0200 Subject: [PATCH 1/3] error handling for autoexec1 --- components/wifi-manager/code.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index fc25b661..8da79343 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -173,7 +173,7 @@ $(document).ready(function(){ $( "#wifi" ).slideDown( "fast", function() {}) }); - $("#autoexec-cb").on("click", function() { + $("input#autoexec-cb").on("click", function() { autoexec = (this.checked)?1:0; $.ajax({ url: '/config.json', @@ -194,7 +194,7 @@ $(document).ready(function(){ }); }); - $("#save-autoexec1").on("click", function() { + $("input#save-autoexec1").on("click", function() { autoexec1 = $("#autoexec1").val(); $.ajax({ @@ -203,12 +203,16 @@ $(document).ready(function(){ method: 'POST', cache: false, headers: { "X-Custom-autoexec1": autoexec1 }, - data: { 'timestamp': Date.now() } + data: { 'timestamp': Date.now() }, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr.status); + console.log(thrownError); + } }); console.log('sent config JSON with headers:', autoexec1); }); - $("#save-gpio").on("click", function() { + $("input#save-gpio").on("click", function() { var headers = {}; $("input.gpio").each(function() { var id = $(this)[0].id; From 6255c5809f38149621c226917732174a2d04fa80 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Thu, 3 Oct 2019 21:20:56 +0200 Subject: [PATCH 2/3] proper error handling for all json posts --- components/wifi-manager/code.js | 47 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 8da79343..0059849b 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -181,7 +181,12 @@ $(document).ready(function(){ method: 'POST', cache: false, headers: { "X-Custom-autoexec": autoexec }, - data: { 'timestamp': Date.now() } + data: { 'timestamp': Date.now() }, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr.status); + console.log(thrownError); + if (thrownError != '') showMessage(thrownError); + } }); console.log('sent config JSON with headers:', autoexec); console.log('now triggering reboot'); @@ -190,7 +195,12 @@ $(document).ready(function(){ dataType: 'json', method: 'POST', cache: false, - data: { 'timestamp': Date.now()} + data: { 'timestamp': Date.now()}, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr.status); + console.log(thrownError); + if (thrownError != '') showMessage(thrownError); + } }); }); @@ -207,6 +217,7 @@ $(document).ready(function(){ error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); + if (thrownError != '') showMessage(thrownError); } }); console.log('sent config JSON with headers:', autoexec1); @@ -231,6 +242,7 @@ $(document).ready(function(){ error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); + if (thrownError != '') showMessage(thrownError); } }); console.log('sent config JSON with headers:', JSON.stringify(headers)); @@ -260,6 +272,7 @@ $(document).ready(function(){ error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); + if (thrownError != '') showMessage(thrownError); } }); console.log('sent config JSON with headers:', JSON.stringify(headers)); @@ -275,7 +288,12 @@ $(document).ready(function(){ method: 'POST', cache: false, headers: { "X-Custom-fwurl": url }, - data: { 'timestamp': Date.now() } + data: { 'timestamp': Date.now() }, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr.status); + console.log(thrownError); + if (thrownError != '') showMessage(thrownError); + } }); enableStatusTimer = true; }); @@ -433,7 +451,12 @@ function performConnect(conntype){ method: 'POST', cache: false, headers: { 'X-Custom-ssid': selectedSSID, 'X-Custom-pwd': pwd }, - data: { 'timestamp': Date.now()} + data: { 'timestamp': Date.now()}, + error: function (xhr, ajaxOptions, thrownError) { + console.log(xhr.status); + console.log(thrownError); + if (thrownError != '') showMessage(thrownError); + } }); //now we can re-set the intervals regardless of result @@ -608,12 +631,7 @@ function checkStatus(){ $("span#flash-status").html(''); } if (data.hasOwnProperty('message') && data['message'] != ''){ - $('#message').html(data['message']); - $("#content").fadeTo("slow", 0.3, function() { - $("#message").show(500).delay(5000).hide(500, function() { - $("#content").fadeTo("slow", 1.0); - }); - }); + showMessage(data['message']); } blockAjax = false; }) @@ -662,3 +680,12 @@ function getConfig() { console.log("failed to fetch config!"); }); } + +function showMessage(message) { + $('#message').html(message); + $("#content").fadeTo("slow", 0.3, function() { + $("#message").show(500).delay(5000).hide(500, function() { + $("#content").fadeTo("slow", 1.0); + }); + }); +} From 56a6fd6e550c40e45208d16490be4105030a8389 Mon Sep 17 00:00:00 2001 From: Christian Herzog Date: Thu, 3 Oct 2019 21:57:41 +0200 Subject: [PATCH 3/3] prevent duplicate messages --- components/wifi-manager/code.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/components/wifi-manager/code.js b/components/wifi-manager/code.js index 0059849b..5abd3ff6 100644 --- a/components/wifi-manager/code.js +++ b/components/wifi-manager/code.js @@ -19,6 +19,7 @@ var commandHeader = 'squeezelite -b 500:2000 -d all=info '; var pname, ver, otapct, otadsc; var blockAjax = false; var blockFlashButton = false; +var lastMsg = ''; var apList = null; var selectedSSID = ""; @@ -631,7 +632,11 @@ function checkStatus(){ $("span#flash-status").html(''); } if (data.hasOwnProperty('message') && data['message'] != ''){ - showMessage(data['message']); + var msg = data['message']; + if (msg != lastMsg) { + showMessage(msg); + lastMsg = msg; + } } blockAjax = false; })