Skip to content

Instantly share code, notes, and snippets.

@laiso
Last active April 6, 2017 12:15
Show Gist options
  • Save laiso/7a551d0fc905a0dbf1f0ca16c0824230 to your computer and use it in GitHub Desktop.
Save laiso/7a551d0fc905a0dbf1f0ca16c0824230 to your computer and use it in GitHub Desktop.
Error Handling in RxSwift
// MARK: Submit Button - action
viewModel.loggedIn.asObservable()
.observeOn(MainScheduler.instance)
.retryWhen { errorObservable -> Observable<Error> in
errorObservable.map { [weak self] error in
let alert = ErrorAlertBuilder(error: error).build()
self?.present(alert, animated: true, completion: nil)
return error
}
}
.subscribe(onNext: { [weak self] in
guard let strongSelf = self else { return }
self?.dismiss(animated: true, completion: {
self?.delegate?.didSignin(strongSelf)
})
})
.addDisposableTo(disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment