aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay <[email protected]>2024-01-31 19:06:16 -0500
committerAjay <[email protected]>2024-01-31 19:06:16 -0500
commitc0bc068a18e0423f69a987c5bcf37bd5b42f1ad7 (patch)
tree4e70ebc6b4bc9139a05847d82f70418a56c3d8e6
parent7cb413db15c89e678785f1ded3f9fdf2ff07f47b (diff)
downloadSponsorBlock-c0bc068a18e0423f69a987c5bcf37bd5b42f1ad7.tar.gz
SponsorBlock-c0bc068a18e0423f69a987c5bcf37bd5b42f1ad7.zip
Handle exceptions for voting
Maybe fixes #1961
-rw-r--r--src/background.ts46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/background.ts b/src/background.ts
index 161ee45a..812482af 100644
--- a/src/background.ts
+++ b/src/background.ts
@@ -222,27 +222,35 @@ async function submitVote(type: number, UUID: string, category: string) {
const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category;
- //publish this vote
- const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection);
-
- if (response.ok) {
- return {
- successType: 1,
- responseText: await response.text()
- };
- } else if (response.status == 405) {
- //duplicate vote
- return {
- successType: 0,
- statusCode: response.status,
- responseText: await response.text()
- };
- } else {
- //error while connect
+ try {
+ const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection);
+
+ if (response.ok) {
+ return {
+ successType: 1,
+ responseText: await response.text()
+ };
+ } else if (response.status == 405) {
+ //duplicate vote
+ return {
+ successType: 0,
+ statusCode: response.status,
+ responseText: await response.text()
+ };
+ } else {
+ //error while connect
+ return {
+ successType: -1,
+ statusCode: response.status,
+ responseText: await response.text()
+ };
+ }
+ } catch (e) {
+ console.error(e);
return {
successType: -1,
- statusCode: response.status,
- responseText: await response.text()
+ statusCode: -1,
+ responseText: ""
};
}
}