guardNotInitialized<R> function

R guardNotInitialized<R>(
  1. R cb()
)

A generic guard wrapper for API calls to handle exceptions.

Implementation

R guardNotInitialized<R>(R Function() cb) {
  try {
    final value = cb();

    if (value is Future) {
      return value.catchError(
        _handleException,
      ) as R;
    }

    return value;
  } catch (error, stackTrace) {
    _handleException(error, stackTrace);
  }
}