Skip to content

Commit

Permalink
disambiguate between invalid and expired start.gg key
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlee337 committed Oct 12, 2024
1 parent acbabc0 commit dc33711
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/main/startgg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ async function wrappedFetch(
}, 1000);
});
}
const keyErr =
response.status === 400 || response.status === 401
? ' ***start.gg API key invalid or expired!***'
: '';
let keyErr = '';
if (response.status === 400) {
keyErr = ' ***start.gg API key invalid!***';
} else if (response.status === 401) {
keyErr = ' ***start.gg API key expired!***';
}
throw new Error(`${response.status} - ${response.statusText}.${keyErr}`);
}

Expand Down
1 change: 1 addition & 0 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,7 @@ function Hello() {
folderNameFormat={folderNameFormat}
setFolderNameFormat={setFolderNameFormat}
setAdminedTournaments={setAdminedTournaments}
showErrorDialog={showErrorDialog}
/>
</>
);
Expand Down
21 changes: 12 additions & 9 deletions src/renderer/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default function Settings({
folderNameFormat,
setFolderNameFormat,
setAdminedTournaments,
showErrorDialog,
}: {
appVersion: string;
latestAppVersion: string;
Expand All @@ -88,6 +89,7 @@ export default function Settings({
folderNameFormat: string;
setFolderNameFormat: (folderNameFormat: string) => void;
setAdminedTournaments: (tournaments: AdminedTournament[]) => void;
showErrorDialog: (errors: string[]) => void;
}) {
const [open, setOpen] = useState(false);
const [copied, setCopied] = useState(false);
Expand Down Expand Up @@ -136,11 +138,6 @@ export default function Settings({
setHasAutoOpened(true);
}

const getTournaments = async () => {
setAdminedTournaments(await window.electron.getTournaments());
setShouldGetTournaments(false);
};

return (
<>
<Tooltip title="Settings">
Expand All @@ -156,24 +153,30 @@ export default function Settings({
fullWidth
open={open}
onClose={async () => {
const promises = [
await Promise.all([
window.electron.setChallongeKey(challongeApiKey),
window.electron.setStartggKey(startggApiKey),
window.electron.setFileNameFormat(fileNameFormat),
window.electron.setFolderNameFormat(folderNameFormat),
];
]);
if (shouldGetTournaments) {
if (
(mode === Mode.STARTGG && startggApiKey) ||
(mode === Mode.CHALLONGE && challongeApiKey)
) {
promises.push(getTournaments());
try {
setAdminedTournaments(await window.electron.getTournaments());
} catch (e: any) {
showErrorDialog([e instanceof Error ? e.message : e]);
return;
} finally {
setShouldGetTournaments(false);
}
} else {
setAdminedTournaments([]);
setShouldGetTournaments(false);
}
}
await Promise.all(promises);
setOpen(false);
}}
>
Expand Down

0 comments on commit dc33711

Please sign in to comment.