From 4bb6cd0dcfb1677346c66df16627b497b7b24ff8 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Sat, 20 Jul 2019 13:26:55 -0400 Subject: [PATCH] Add message when connection failed when trying to vote. --- background.js | 13 +++++++++++-- content.js | 3 +++ popup.js | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/background.js b/background.js index ec126b20..4feb48bd 100644 --- a/background.js +++ b/background.js @@ -87,7 +87,7 @@ function addSponsorTime(time) { function submitVote(type, UUID, callback) { getUserID(function(userID) { //publish this vote - sendRequestToUser('GET', "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp) { + sendRequestToUser('GET', "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + "&type=" + type, function(xmlhttp, error) { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { callback({ successType: 1 @@ -97,6 +97,11 @@ function submitVote(type, UUID, callback) { callback({ successType: 0 }); + } else if (error) { + //error while connect + callback({ + successType: -1 + }); } }) }) @@ -180,7 +185,11 @@ function sendRequestToUser(type, address, callback) { xmlhttp.open(type, serverAddress + address, true); xmlhttp.onreadystatechange = function () { - callback(xmlhttp); + callback(xmlhttp, false); + }; + + xmlhttp.onerror = function(ev) { + callback(xmlhttp, true); }; //submit this request diff --git a/content.js b/content.js index 2bea7df8..b6f3ed9f 100644 --- a/content.js +++ b/content.js @@ -390,6 +390,9 @@ function vote(type, UUID) { } else if (response.successType == 0) { //failure: duplicate vote votingError("It seems you've already voted before", UUID) + } else if (response.successType == -1) { + //failure: duplicate vote + votingError("A connection error has occured.", UUID) } } }); diff --git a/popup.js b/popup.js index cf4d54cf..fdf23dc9 100644 --- a/popup.js +++ b/popup.js @@ -400,6 +400,9 @@ function vote(type, UUID) { } else if (response.successType == 0) { //failure: duplicate vote addVoteMessage("You have already voted this way before.", UUID) + } else if (response.successType == -1) { + //failure: duplicate vote + addVoteMessage("A connection error has occured.", UUID) } } });