Don't try to reload every three seconds in case of 401 (#1104)
This commit is contained in:
parent
075b8a739a
commit
a18872340f
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue