withReplacedSecretChallengeException<T> method

Future<T> withReplacedSecretChallengeException<T>(
  1. Future<T> fn()
)

Replaces challenge-related exceptions by email-specific exceptions.

Implementation

Future<T> withReplacedSecretChallengeException<T>(
  final Future<T> Function() fn,
) async {
  try {
    return await fn();
  } on SecretChallengeException catch (e) {
    throw switch (e) {
      ChallengeRequestNotFoundException() =>
        EmailAccountRequestNotFoundException(),
      ChallengeAlreadyUsedException() =>
        EmailAccountRequestVerificationCodeAlreadyUsedException(),
      ChallengeInvalidVerificationCodeException() =>
        EmailAccountRequestInvalidVerificationCodeException(),
      ChallengeExpiredException() =>
        EmailAccountRequestVerificationExpiredException(),
      ChallengeNotVerifiedException() =>
        EmailAccountRequestNotVerifiedException(),
      ChallengeInvalidCompletionTokenException() =>
        EmailAccountRequestInvalidVerificationCodeException(),
      ChallengeRateLimitExceededException() =>
        EmailAccountRequestVerificationTooManyAttemptsException(),
    };
  }
}