OnError

  • Centralizes the business exceptions generated by Effect, whether it is a synchronous function or an asynchronous function. With a unified exception handling mechanism, we can stand on a higher level of abstraction and make reasonable simplifications of business code.
  • Sample Code
  1. bool onMessageError(Exception e, Context<String> ctx) {
  2. if(e is BizException) {
  3. ///do some toast
  4. return true;
  5. }
  6. return false;
  7. }
  8. class MessageComponent extends Component<String> {
  9. MessageComponent(): super(
  10. view: buildMessageView,
  11. effect: buildEffect(),
  12. reducer: buildMessageReducer(),
  13. onError: onMessageError,
  14. );
  15. }