From f81ae23bb0dc14339dc26a45abd48179a5b28969 Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Sat, 22 Aug 2026 16:58:28 -0400 Subject: [PATCH] Setup fail safes for loadTrainStatus() --- Sources/AmtrakStatus/ContentView.swift | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Sources/AmtrakStatus/ContentView.swift b/Sources/AmtrakStatus/ContentView.swift index 2048c47..1aceb27 100644 --- a/Sources/AmtrakStatus/ContentView.swift +++ b/Sources/AmtrakStatus/ContentView.swift @@ -9,7 +9,14 @@ struct ContentView: View { @State var errorMessage: String? var body: some View { - + HStack { + + }.padding() + .onAppear { + Task { + await loadTrainStatus(forStationCode: normalizedStationCode) + } + } } var normalizedStationCode: String { @@ -27,7 +34,23 @@ struct ContentView: View { defer { isLoading = false } do { + let trainNumbers = try await client.fetchStationTrainNumbers( + stationCode: code + ) + guard !trainNumbers.isEmpty else { + errorMessage = "Station \(code) has no trains listed right now" + rows = [] + return + } + + } catch AmtrakError.stationNotFound(let code) + { + errorMessage = "Station \(code) not foudn" + rows = [] + } catch { + errorMessage = "Couldn't load train status: \(error.localizedDescription)" + rows = [] } } }