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:
mini-bomba
2025-08-21 19:27:32 +02:00
parent fd2826a80d
commit bf6626f4b3
18 changed files with 239 additions and 157 deletions

View File

@@ -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));
}
}