safeUpdateAsyncWithHandler<T> static method

Future<T> safeUpdateAsyncWithHandler<T>(
  1. Future<T> update(),
  2. Future<T> onError(
    1. Object error,
    2. StackTrace stackTrace
    )
)

Execute an async function with custom error handler

Implementation

static Future<T> safeUpdateAsyncWithHandler<T>(
  Future<T> Function() update,
  Future<T> Function(Object error, StackTrace stackTrace) onError,
) async {
  try {
    return await update();
  } catch (e, stackTrace) {
    Logger.error('Async state update error (custom handler)', e);
    Logger.debug('Stack trace', stackTrace);
    return await onError(e, stackTrace);
  }
}