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.  
  9. class MessageComponent extends Component<String> {
  10. MessageComponent(): super(
  11. view: buildMessageView,
  12. effect: buildEffect(),
  13. reducer: buildMessageReducer(),
  14. onError: onMessageError,
  15. );
  16. }