platformException<T> function

PlatformResult<T> platformException<T>(
  1. Object error, {
  2. PlatformFailure fallback = PlatformFailure.operationFailed,
})

Implementation

PlatformResult<T> platformException<T>(
  Object error, {
  PlatformFailure fallback = PlatformFailure.operationFailed,
}) {
  if (error is MissingPluginException || error is UnsupportedError) {
    return PlatformResult.failure(PlatformFailure.unsupported, '$error');
  }
  if (error is PlatformException) {
    final code = error.code.toLowerCase();
    if (code.contains('denied') ||
        code.contains('permission') ||
        code.contains('restricted')) {
      return PlatformResult.failure(PlatformFailure.permissionDenied, '$error');
    }
  }
  if (error is FileSystemException) {
    return PlatformResult.failure(PlatformFailure.operationFailed, '$error');
  }
  return PlatformResult.failure(fallback, '$error');
}