-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you handle when internet disconnect? #46
Comments
func request(_ token: Target) -> Observable<Moya.Response> {
let actualRequest = provider.rx.request(token)
return online
// .ignore(value: false) // Wait until we're online
.take(1) // Take 1 to make sure we only invoke the API once.
.flatMap { _ in // Turn the online state into a network request
return actualRequest
.filterSuccessfulStatusCodes()
.do(onSuccess: { (response) in
}, onError: { (error) in
if let error = error as? MoyaError {
switch error {
case .statusCode(let response):
if response.statusCode == 401 {
// Unauthorized
if AuthManager.shared.hasValidToken {
AuthManager.removeToken()
Application.shared.presentInitialScreen(in: Application.shared.window)
}
}
case .underlying(let error, _):
if let error = error as? AFError {
switch error {
case .sessionTaskFailed(let error as NSError):
if error.domain == NSURLErrorDomain && error.code == NSURLErrorTimedOut {
print("timeout")
} else if error.domain == NSURLErrorDomain && error.code == NSURLErrorDataNotAllowed {
print("no connect")
}
default:
break
}
}
default:
break
}
}
})
}
} try this function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Can you handle when I disconnect internet and try login button or other API request. The loading will forever and user can not touch any more.
To Reproduce
Steps to reproduce the behavior:
The text was updated successfully, but these errors were encountered: