mirror of
https://github.com/tonytins/amtkstat.git
synced 2026-10-24 05:32:54 -04:00
Setup fail safes for loadTrainStatus()
This commit is contained in:
parent
df5b326e30
commit
f81ae23bb0
1 changed files with 24 additions and 1 deletions
|
|
@ -9,7 +9,14 @@ struct ContentView: View {
|
||||||
@State var errorMessage: String?
|
@State var errorMessage: String?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
HStack {
|
||||||
|
|
||||||
|
}.padding()
|
||||||
|
.onAppear {
|
||||||
|
Task {
|
||||||
|
await loadTrainStatus(forStationCode: normalizedStationCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var normalizedStationCode: String {
|
var normalizedStationCode: String {
|
||||||
|
|
@ -27,7 +34,23 @@ struct ContentView: View {
|
||||||
defer { isLoading = false }
|
defer { isLoading = false }
|
||||||
|
|
||||||
do {
|
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 = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue