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
- bool onMessageError(Exception e, Context<String> ctx) {
- if(e is BizException) {
- ///do some toast
- return true;
- }
- return false;
- }
-
- class MessageComponent extends Component<String> {
- MessageComponent(): super(
- view: buildMessageView,
- effect: buildEffect(),
- reducer: buildMessageReducer(),
- onError: onMessageError,
- );
- }