getExceptionInfo function

Future<ExceptionInfo> getExceptionInfo(
  1. PlatformException error,
  2. List<Checkpoint> checkpoints
)

Implementation

Future<ExceptionInfo> getExceptionInfo(
    PlatformException error, List<Checkpoint> checkpoints) async {
  if (error.code == 'android-sync-account-not-available') {
    final deviceInfo = DeviceInfoPlugin();
    final androidInfo = await deviceInfo.androidInfo;
    if (androidInfo.isPhysicalDevice) {
      return const ExceptionInfo(
        title: 'SyncAccountNotAvailableException',
        description:
            'This issue should not happen on a physical device. Please contact the package authors.',
        platforms: ['Android'],
        suggestions: [],
      );
    }
  }

  if (error.code == 'domain-not-associated' &&
      checkpoints.any((cp) =>
          cp.name.contains('AASA') && cp.type == CheckpointType.success)) {
    return const ExceptionInfo(
      title: 'DomainNotAssociatedException',
      description:
          'In your case it is caused by Apple CDN caching of the AASA file; check docs for the `?mode=developer` parameter.',
      platforms: ['iOS'],
      suggestions: [
        'Clear any CDN caches or use the `?mode=developer` flag.',
      ],
    );
  }

  // Standard lookup
  if (exceptionInfos.containsKey(error.code)) {
    return exceptionInfos[error.code]!;
  }

  // Unhandled authenticator exceptions
  if (error.code.startsWith('android-unhandled') ||
      error.code.startsWith('ios-unhandled')) {
    return ExceptionInfo(
      title: 'UnhandledAuthenticatorException',
      description:
          'Thrown when an authenticator-thrown exception isn’t handled by this package (code: ${error.code}).',
      platforms: ['Android', 'iOS'],
      suggestions: ['Report this exception to the package authors.'],
    );
  }

  // Fallback
  return ExceptionInfo(
    title: error.code,
    description: 'No additional info available.',
    platforms: [],
    suggestions: [],
  );
}