Execute UI action upon Future failure

24 views
Skip to first unread message

John Murdoch

unread,
Dec 30, 2014, 2:56:06 PM12/30/14
to mac...@googlegroups.com

Hi,

I'm trying to show a toast when a Future fails:

   def attemptLogin(): Ui[Any] = {
if (password.get.getText.length == 0 || password.get.getText.length == 0) {
toast("Provide username and password") <~ fry
} else {
val loginResult = service.login(username.get.getText.toString, password.get.getText.toString)

loginResult.onComplete {
case Success(token) =>
// do something
        case Failure(t) =>
error(s"Login failed '${t.getMessage}'", t)

Ui {
toast(s"Login failed: ${t.getMessage}") <~ fry // <---- this doesn't appear
}.run
}

Ui{}
}


     // when creating view
        w[Button] <~ wire(signIn) <~ text("Sign In") <~ On.click({
attemptLogin()
})

However, the toast never appears, even though the execution path is invoked (I see the "Login failed ..." in logs). 

I also tried `runUi { toast("...") }` with same results.

login method is a 'dispatch' HTTP library call.

Regards,
John

Nick Stanchenko

unread,
Dec 30, 2014, 8:41:07 PM12/30/14
to mac...@googlegroups.com
Hi,

`toast(...) <~ fry` return a Ui, so you don’t need to wrap it into another one. `runUi(toast(...) <~ fry)` should do the trick (the difference from your second example is that you missed the `fry`).

Let me know if that worked,
Nick

John Murdoch

unread,
Dec 31, 2014, 3:44:39 AM12/31/14
to mac...@googlegroups.com
Nick,

No, it did not. 

I tried:

case Failure(t) =>
info("Got failure")
runUi {
info("About to show toast")

toast(s"Login failed: ${t.getMessage}") <~ fry
}

And in logs I see:

12-31 10:40:58.252  21805-22711/myapp I/:ctivity.LoginActivity﹕ Got failure
12-31 10:40:58.252  21805-22711/myapp I/:ctivity.LoginActivity﹕ About to show toast


But no toast appears :(. 

Regards,
John



Nick Stanchenko

unread,
Dec 31, 2014, 2:11:39 PM12/31/14
to mac...@googlegroups.com
John,

Would it be possible for you to produce a self-contained example? I don’t see why this wouldn’t work.

Nick

John Murdoch

unread,
Jan 1, 2015, 7:35:52 AM1/1/15
to mac...@googlegroups.com
Nick,

I changed proguard config and the issue went away (using same source code). Thanks for your help.

Regards,
John

Reply all
Reply to author
Forward
0 new messages