Forward error

This commit is contained in:
Thomas Ricouard 2022-11-25 12:01:55 +01:00
parent ec8de5fb83
commit e91a8b4b0a
2 changed files with 5 additions and 5 deletions

View file

@ -13,8 +13,8 @@ public struct TimelineView: View {
switch viewModel.state {
case .loading:
loadingRow
case .error:
Text("An error occurred, please try to refresh")
case let .error(error):
Text(error.localizedDescription)
case let .display(statuses, nextPageState):
ForEach(statuses) { status in
StatusRowView(status: status)

View file

@ -9,7 +9,7 @@ class TimelineViewModel: ObservableObject {
}
case loading
case display(statuses: [Status], nextPageState: State.PadingState)
case error
case error(error: Error)
}
private let client: Client
@ -30,7 +30,7 @@ class TimelineViewModel: ObservableObject {
statuses = try await client.fetchArray(endpoint: Timeline.pub(sinceId: nil))
state = .display(statuses: statuses, nextPageState: .hasNextPage)
} catch {
print(error.localizedDescription)
state = .error(error: error)
}
}
@ -42,7 +42,7 @@ class TimelineViewModel: ObservableObject {
statuses.append(contentsOf: newStatuses)
state = .display(statuses: statuses, nextPageState: .hasNextPage)
} catch {
print(error.localizedDescription)
state = .error(error: error)
}
}
}