aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2021-01-26 21:57:43 -0500
committerAjay Ramachandran <[email protected]>2021-01-26 21:57:43 -0500
commit67f27986727c6c1355e90e6b792c9d77cc1916c2 (patch)
treef41da719ead9f7af1ac01a819250c6bc52e913c8
parent41fee58ab90717dd1f05ecbebeb887ae047877cf (diff)
downloadSponsorBlock-67f27986727c6c1355e90e6b792c9d77cc1916c2.tar.gz
SponsorBlock-67f27986727c6c1355e90e6b792c9d77cc1916c2.zip
Add error message from server when voting
-rw-r--r--src/background.ts9
-rw-r--r--src/content.ts4
-rw-r--r--src/popup.ts8
-rw-r--r--src/utils.ts5
4 files changed, 15 insertions, 11 deletions
diff --git a/src/background.ts b/src/background.ts
index ea011576..b562c4e7 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -125,19 +125,22 @@ async function submitVote(type: number, UUID: string, category: string) {
if (response.ok) {
return {
- successType: 1
+ successType: 1,
+ responseText: await response.text()
};
} else if (response.status == 405) {
//duplicate vote
return {
successType: 0,
- statusCode: response.status
+ statusCode: response.status,
+ responseText: await response.text()
};
} else {
//error while connect
return {
successType: -1,
- statusCode: response.status
+ statusCode: response.status,
+ responseText: await response.text()
};
}
}
diff --git a/src/content.ts b/src/content.ts
index 048d8898..1eaea00e 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -1373,7 +1373,7 @@ function vote(type: number, UUID: string, category?: string, skipNotice?: SkipNo
//success (treat rate limits as a success)
skipNotice.afterVote.bind(skipNotice)(utils.getSponsorTimeFromUUID(sponsorTimes, UUID), type, category);
} else if (response.successType == -1) {
- skipNotice.setNoticeInfoMessage.bind(skipNotice)(utils.getErrorMessage(response.statusCode))
+ skipNotice.setNoticeInfoMessage.bind(skipNotice)(utils.getErrorMessage(response.statusCode, response.responseText))
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
}
}
@@ -1500,7 +1500,7 @@ async function sendSubmitMessage(): Promise<void> {
document.getElementById("submitButton").style.animation = "unset";
(<HTMLImageElement> document.getElementById("submitImage")).src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
- alert(utils.getErrorMessage(response.status) + "\n\n" + (response.responseText));
+ alert(utils.getErrorMessage(response.status, response.responseText));
}
}
diff --git a/src/popup.ts b/src/popup.ts
index db34325c..f28589a7 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -548,7 +548,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
PageElements.sponsorTimesContributionsContainer.classList.remove("hidden");
} else {
- PageElements.setUsernameStatus.innerText = utils.getErrorMessage(response.status);
+ PageElements.setUsernameStatus.innerText = utils.getErrorMessage(response.status, response.responseText);
}
});
@@ -575,7 +575,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
function vote(type, UUID) {
//add loading info
- addVoteMessage(chrome.i18n.getMessage("Loading"), UUID)
+ addVoteMessage(chrome.i18n.getMessage("Loading"), UUID);
//send the vote message to the tab
chrome.runtime.sendMessage({
@@ -587,9 +587,9 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
//see if it was a success or failure
if (response.successType == 1 || (response.successType == -1 && response.statusCode == 429)) {
//success (treat rate limits as a success)
- addVoteMessage(chrome.i18n.getMessage("voted"), UUID)
+ addVoteMessage(chrome.i18n.getMessage("voted"), UUID);
} else if (response.successType == -1) {
- addVoteMessage(utils.getErrorMessage(response.statusCode), UUID)
+ addVoteMessage(utils.getErrorMessage(response.statusCode, response.responseText), UUID);
}
}
});
diff --git a/src/utils.ts b/src/utils.ts
index 6d7af44d..fd47b27c 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -286,8 +286,9 @@ class Utils {
* @param {int} statusCode
* @returns {string} errorMessage
*/
- getErrorMessage(statusCode: number): string {
+ getErrorMessage(statusCode: number, responseText: string): string {
let errorMessage = "";
+ const postFix = (responseText ? "\n\n" + responseText : "");
if([400, 429, 409, 502, 0].includes(statusCode)) {
//treat them the same
@@ -299,7 +300,7 @@ class Utils {
errorMessage = chrome.i18n.getMessage("connectionError") + statusCode;
}
- return errorMessage;
+ return errorMessage + postFix;
}
/**