Skip to content

Commit

Permalink
fix: health checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Lombardoc4 committed Jun 10, 2024
1 parent 4027a82 commit ba9c46f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/app/api/fetchEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,22 @@ export const fetchEventList = atomEffect(
const season = get(SeasonState);
const params = season && `?year=${season}`;

// TODO: Prevent fetch if not connected
// ! Bug with serverConnectedState not updating
// const connected = get(serverConnectedState);
// if (!connected) {
// return;
// }

// Fetch event list from api
fetchAPI('schedule' + params).then(
(res: DataConfigSchema['schedule'] | ServerErrorResponse) => {
const schedule = res as DataConfigSchema['schedule'];
const error = res as ServerErrorResponse;

// *** If errors specific prop, detail, update serverErrorState
if (error.detail) {
if (!schedule) return;
if (error && error.detail) {
set(serverErrorState, error.detail[0].msg);
return;
}
Expand All @@ -43,7 +51,7 @@ export const fetchEventList = atomEffect(

set(EventListState, completedEvents);

// *** If no season sync default year with server provided season
// *** If no season, sync default year with server provided season
if (!season) {
set(SeasonState, schedule.year);
}
Expand Down
5 changes: 3 additions & 2 deletions src/app/api/fetchHealth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ export const fetchHealth = atomEffect(

// Fetch event list from api
fetchAPI('health').then((res: { status: string } | ServerErrorResponse) => {
const success = res as { status: string };
const error = res as ServerErrorResponse;

if ('status' in res) {
if (success && success.status) {
set(serverConnectedState, true);
return;
}

// *** If errors specific prop, detail, update serverErrorState
if (error.detail) {
if (error && error.detail) {
set(serverErrorState, error.detail[0].msg);
return;
}
Expand Down

0 comments on commit ba9c46f

Please sign in to comment.