convertToUserFacingException function

Exception? convertToUserFacingException(
  1. Object error
)

Converts server exceptions to user-friendly error messages.

Returns a user-friendly exception or message for exceptions that should be shown to the user. Returns null for internal errors that shouldn't be exposed to users (e.g., StateError, internal server errors, network errors).

Implementation

Exception? convertToUserFacingException(Object error) {
  if (error is UserFacingException) return error;
  if (error is GoogleIdTokenVerificationException) {
    return UserFacingException(
      'An error occurred while verifying the Google ID token. Please check '
      'your Google account and try again. If the problem persists, please '
      'contact support.',
      originalException: error,
    );
  }
  if (error is GoogleSignInException) {
    return UserFacingException(
      'An error occurred while signing in with Google. Please try again later. '
      'If the problem persists, please contact support.',
      originalException: error,
    );
  }
  if (error is ServerpodClientException) {
    return UserFacingException.fromServerpodClientException(error);
  }
  return null;
}