mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-14 07:27:05 +03:00
Improve error handling
- pass errors from background threads back to clients - log all HTTP request errors and display them to the user where possible
This commit is contained in:
@@ -3,7 +3,7 @@ import * as CompileConfig from "../config.json";
|
||||
import Config from "./config";
|
||||
import { Registration } from "./types";
|
||||
import "content-scripts-register-polyfill";
|
||||
import { sendRealRequestToCustomServer, setupBackgroundRequestProxy } from "../maze-utils/src/background-request-proxy";
|
||||
import { sendRealRequestToCustomServer, serializeOrStringify, setupBackgroundRequestProxy } from "../maze-utils/src/background-request-proxy";
|
||||
import { setupTabUpdates } from "../maze-utils/src/tab-updates";
|
||||
import { generateUserID } from "../maze-utils/src/setup";
|
||||
|
||||
@@ -227,33 +227,16 @@ async function submitVote(type: number, UUID: string, category: string, videoID:
|
||||
|
||||
try {
|
||||
const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&videoID=" + videoID + "&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: -1,
|
||||
responseText: ""
|
||||
status: response.status,
|
||||
ok: response.ok,
|
||||
responseText: await response.text(),
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Error while voting:", e);
|
||||
return {
|
||||
error: serializeOrStringify(e),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -263,4 +246,4 @@ async function asyncRequestToServer(type: string, address: string, data = {}) {
|
||||
const serverAddress = Config.config.testingServer ? CompileConfig.testingServerAddress : Config.config.serverAddress;
|
||||
|
||||
return await (sendRealRequestToCustomServer(type, serverAddress + address, data));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user