2

In Diode, how do one handle a Future.failure in an effect? The doc (https://ochrons.github.io/diode/usage/Effects.html), it is clear how a success value from the Ajax call is used to update the model with a Pot.Ready, but I wonder how one can catch a failure and update a Pot.Failed instead.

4

1 回答 1

1

对于普通效果,您需要使用 和 的组合将成功和失败都转换FutureFuture合适的动作。例如:maprecover

val eff = Effect(Ajax.get(url)
  .map(r => NewMessages(r.responseText)))
  .recover { case e => MessageLoadingFailed(e.getMessage) }
)

如果您正在使用AsyncAction(或派生的PotAction),它会提供一个辅助方法effect来自动处理未来的故障并创建一个PotFailed状态。

于 2017-01-19T18:47:05.873 回答