Here is my code below. I need to call api multiple times until internet signal is on.
buttonAction.do(onNext: { [weak self] in
self?.activity.startAnimating()
apiManager.callApi()
.do(onNext: { [weak self] in
self?.activity.stopAnimating()
},onError: { [weak self ] error in
if let error = error as? NoNetwork {
self?.activity.stopAnimating(errorInfo:error,presentationStyle:.alert)
// here alert will be appear. On click ok button, need to trigger the API() again
}
})
.subscribe().disposed(by:bag)
Note that you didn't say how you want to deal with any other type of error so the code below just ignores them... Remove the
filterif you want to show the alert for all errors.The
presentScenefunction comes from my CLE library. In this codeactivityis a standardUIActivityIndicatorViewinstead of whatever you are using.