Skip to content

Commit

Permalink
handle startgg 503s a lil better
Browse files Browse the repository at this point in the history
- block report, copy, delete on report success
- retry startgg 500/502/503/504s once

fixes #33
  • Loading branch information
jmlee337 committed May 8, 2024
1 parent 9015401 commit 80bf2e9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/main/startgg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ async function wrappedFetch(
): Promise<Response> {
const response = await fetch(input, init);
if (!response.ok) {
if (
response.status === 500 ||
response.status === 502 ||
response.status === 503 ||
response.status === 504
) {
return new Promise((resolve, reject) => {
setTimeout(async () => {
const retryResponse = await fetch(input, init);
if (!retryResponse.ok) {
reject(
new Error(
`${retryResponse.status} - ${retryResponse.statusText}`,
),
);
} else {
resolve(retryResponse);
}
}, 1000);
});
}
throw new Error(`${response.status} - ${response.statusText}`);
}

Expand Down
5 changes: 2 additions & 3 deletions src/renderer/SetControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,10 @@ export default function SetControls({
onClick={async () => {
setReporting(true);
try {
const promises = [reportSet(startggSet, set.state === 3)];
await reportSet(startggSet, set.state === 3);
if (reportSettings.alsoCopy) {
promises.push(copyReplays());
await copyReplays();
}
await Promise.all(promises);
if (reportSettings.alsoCopy && reportSettings.alsoDelete) {
await deleteReplays();
}
Expand Down

0 comments on commit 80bf2e9

Please sign in to comment.