Don't try to reload every three seconds in case of 401 (#1104)

This commit is contained in:
Nathan Mattes 2023-08-21 13:20:13 +02:00
parent 075b8a739a
commit a18872340f
3 changed files with 21 additions and 8 deletions

View File

@ -8,6 +8,7 @@
import Foundation
import GameplayKit
import MastodonSDK
import enum NIOHTTP1.HTTPResponseStatus
extension DiscoveryCommunityViewModel {
class State: GKState {
@ -161,7 +162,12 @@ extension DiscoveryCommunityViewModel.State {
viewModel.didLoadLatest.send()
} catch {
await enter(state: Fail.self)
if let error = error as? Mastodon.API.Error,
[HTTPResponseStatus.unauthorized, .notFound].contains(error.httpResponseStatus) {
await enter(state: NoMore.self)
} else {
await enter(state: Fail.self)
}
}
} // end Task
} // end func

View File

@ -170,9 +170,13 @@ extension DiscoveryNewsViewModel.State {
viewModel.links = links
viewModel.didLoadLatest.send()
} catch {
if let error = error as? Mastodon.API.Error, error.httpResponseStatus.code == 404 {
viewModel.isServerSupportEndpoint = false
await enter(state: NoMore.self)
if let error = error as? Mastodon.API.Error {
if error.httpResponseStatus == .notFound {
viewModel.isServerSupportEndpoint = false
await enter(state: NoMore.self)
} else if error.httpResponseStatus == .unauthorized {
await enter(state: NoMore.self)
}
} else {
await enter(state: Fail.self)
}

View File

@ -177,10 +177,13 @@ extension DiscoveryPostsViewModel.State {
viewModel.didLoadLatest.send()
} catch {
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): fetch posts fail: \(error.localizedDescription)")
if let error = error as? Mastodon.API.Error, error.httpResponseStatus.code == 404 {
viewModel.isServerSupportEndpoint = false
await enter(state: NoMore.self)
if let error = error as? Mastodon.API.Error {
if error.httpResponseStatus == .notFound {
viewModel.isServerSupportEndpoint = false
await enter(state: NoMore.self)
} else if error.httpResponseStatus == .unauthorized {
await enter(state: NoMore.self)
}
} else {
await enter(state: Fail.self)
}