Skip to content
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

How to know which task fails in chain of tasks? #67

Open
Igorsnaki opened this issue Nov 28, 2017 · 0 comments
Open

How to know which task fails in chain of tasks? #67

Igorsnaki opened this issue Nov 28, 2017 · 0 comments

Comments

@Igorsnaki
Copy link

Igorsnaki commented Nov 28, 2017

Hi all!
Thanks for really helpful lib!

Can anybody help me?

I have chain of 3 tasks ( request to BE) .
Every task/request can return error with code 401 . But I need to know which task failed , because in case 401 I need to perform different steps depending on which task failed.

Code sample:

        let verifyTask = interactor.verifySMSCode(verificationID: verification.codeID, code: smsCode)
        verifyTask.continueOnSuccessWithTask { token -> Task<LoginResponse> in
            self.interactor.saveSMSToken(token: token)
            return self.interactor.login(phone: self.user.phoneNumber)
            }.continueOnSuccessWithTask { loginResponse -> Task<UserDetails> in
                self.interactor.saveAuthData(authData: loginResponse)
                return self.interactor.requestUserDetails(userID: loginResponse.userID)
            }.continueOnSuccessWith(Executor.mainThread) { [weak self] userDetails in
                self?.view.hideActivityIndicator()
                self?.interactor.saveUserDetails(userDetails: userDetails)
                self?.moduleOutput.didLoginSuccessfuly()
            }.continueOnErrorWith(Executor.mainThread) { [weak self] error in
                self?.view.hideActivityIndicator()
                if (error as NSError).code == 401 {
                   // every of 3 requests / task can return me error code == 401 
                   // How can I understand which of previous 3 task failed??? 
                }
                self?.view.showError(title: nil, message: error.localizedDescription, buttonTitile: "OK")
        }

Are there any ways to separate which task are failed in continueOnErrorWith block ??

P.S. I want to use chain of tasks to make code look better.
I don't wont to use :

        verifyTask.continueWith { task in
            if let result = task.result {
                self.interactor.login(phone: user.phoneNumber).continueWith { task in
                    self.interactor.requestUserDetails(userID: result.userID).continueWith {
                        if ///
                    }
                }
            } else if let err = task.error {
                //
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant