Skip to content

Commit

Permalink
Fix an issue where the system would be waiting for the API (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gum-Joe committed Jul 4, 2022
1 parent da2e915 commit cb398d8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion frontend/src/components/SiteContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,13 @@ export default class SiteContainer extends Component<SiteProps, TheState> {
// Use the new API

try {
const apiRes = await fetch(this.props.iiwaURL);
// Controller timeout from https://thewebdev.info/2022/04/21/how-to-set-request-timeout-with-fetch-api/
// TODO: REMOVE WHEN API FUNCTIONAL!
throw new Error("API non-functional!");
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 500);
const apiRes = await fetch(this.props.iiwaURL, { signal: controller.signal });
clearTimeout(timeoutId);
const apiResJSON: IsItWeekAReturn = await apiRes.json();
if (!apiResJSON.week || !("isWeekend" in apiResJSON)) {
throw new Error("One or both of week or isWeekend not in response");
Expand Down

0 comments on commit cb398d8

Please sign in to comment.