Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/train-routes/train-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ export const useTrainRoutesStore = create<TrainRoutesStore>((set, get) => ({
}
// We couldn't find routes for the requested date.
set({ resultType: "not-found", status: "done" })
throw new Error("Not found")
// "No routes" is an expected UI state, not an exceptional failure.
return []
Comment on lines +91 to +92
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Returning an empty array instead of throwing is a good improvement for handling expected 'no results' states. However, there is a side effect regarding the UI logic in RouteListScreen:

  1. UI Regression: Previously, when this function threw an error, the screen's onError handler would only set resultType to "not-found" if the total routeData was empty. Now, because getRoutes updates the store's resultType unconditionally on line 90 and returns successfully, the NoTrainsFoundMessage (which is a full-screen empty state) will be displayed at the bottom of the list whenever a 'load more' request for a subsequent date fails to find trains, even if the list already contains results from previous dates.
  2. Stale Data: The store's routes state is not cleared on line 90. If a previous search was successful, the store will continue to hold those routes even though the current search returned no results.

Consider making the state updates conditional or moving them to the caller to ensure the UI behaves correctly in aggregated views.

},
}))

Expand Down
Loading