Skip to content

Commit

Permalink
fix(StopPage): Log errors from fetching data (#1998)
Browse files Browse the repository at this point in the history
  • Loading branch information
kotva006 authored Apr 22, 2024
1 parent c3bbc21 commit b1f4277
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions assets/ts/helpers/use-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type FetchAction<T> =
export interface FetchState<T> {
status: FetchStatus;
data?: T;
errorData?: string;
}

const createInitialState = <T>(): FetchState<T> => ({
Expand Down
2 changes: 1 addition & 1 deletion assets/ts/hooks/useStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const fetchFacilityData = async (url: string): Promise<Facility[]> =>
const useStop = (stopId: string): FetchState<Stop> => {
const { data, error } = useSWR<Stop>(`/api/stop/${stopId}`, fetchData);
if (error) {
return { status: FetchStatus.Error };
return { status: FetchStatus.Error, errorData: error };
}
return { status: FetchStatus.Data, data };
};
Expand Down
11 changes: 8 additions & 3 deletions assets/ts/stop/components/StopPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ const StopPage = ({
FetchStatus.Error
)
) {
// TODO: get the actual error message here and/or throw the Error from the
// fetching hooks themselves
throw new Error();
const errorMessage = [
stopResult.errorData,
routesResult.errorData,
facilities.errorData
]
.filter(error => error === undefined)
.join(" ");
throw new Error(errorMessage);
}

// Return loading indicator while waiting on data fetch
Expand Down

0 comments on commit b1f4277

Please sign in to comment.