FirebaseAuthError.fromServerError constructor

FirebaseAuthError.fromServerError(
  1. String serverErrorCode, [
  2. String? message,
  3. dynamic rawServerResponse
])

Creates the developer-facing error corresponding to the backend error code.

Implementation

factory FirebaseAuthError.fromServerError(
  String serverErrorCode, [
  String? message,
  dynamic rawServerResponse,
]) {
  // serverErrorCode could contain additional details:
  // ERROR_CODE : Detailed message which can also contain colons
  final colonSeparator = serverErrorCode.indexOf(':');
  String? customMessage;
  if (colonSeparator != -1) {
    customMessage = serverErrorCode.substring(colonSeparator + 1).trim();
    serverErrorCode = serverErrorCode.substring(0, colonSeparator).trim();
  }

  customMessage ??= message;
  // If not found, default to internal error.
  switch (serverErrorCode) {
    case 'CLAIMS_TOO_LARGE':
      // Claims payload is too large.
      return FirebaseAuthError.claimsTooLarge(customMessage);
    case 'CONFIGURATION_NOT_FOUND':
      // Project not found.
      return FirebaseAuthError.projectNotFound(customMessage);
    case 'INSUFFICIENT_PERMISSION':
      // Provided credential has insufficient permissions.
      return FirebaseAuthError.insufficientPermission(customMessage);
    case 'INVALID_CONTINUE_URI':
      // ActionCodeSettings missing continue URL.
      return FirebaseAuthError.invalidContinueUri(customMessage);
    case 'INVALID_DYNAMIC_LINK_DOMAIN':
      // Dynamic link domain in provided ActionCodeSettings is not authorized.
      return FirebaseAuthError.invalidDynamicLinkDomain(customMessage);
    case 'DUPLICATE_EMAIL':
      // uploadAccount provides an email that already exists.
      return FirebaseAuthError.emailAlreadyExists(customMessage);
    case 'DUPLICATE_LOCAL_ID':
      // uploadAccount provides a localId that already exists.
      return FirebaseAuthError.uidAlreadyExists(customMessage);
    case 'EMAIL_EXISTS':
      // setAccountInfo email already exists.
      return FirebaseAuthError.emailAlreadyExists(customMessage);
    case 'FORBIDDEN_CLAIM':
      // Reserved claim name.
      return FirebaseAuthError.forbiddenClaim(customMessage);
    case 'INVALID_CLAIMS':
      // Invalid claims provided.
      return FirebaseAuthError.invalidClaims(customMessage);
    case 'INVALID_DURATION':
      // Invalid session cookie duration.
      return FirebaseAuthError.invalidSessionCookieDuration(customMessage);
    case 'INVALID_EMAIL':
      // Invalid email provided.
      return FirebaseAuthError.invalidEmail(customMessage);
    case 'INVALID_ID_TOKEN':
      // Invalid ID token provided.
      return FirebaseAuthError.invalidIdToken(customMessage);
    case 'INVALID_PAGE_SELECTION':
      // Invalid page token.
      return FirebaseAuthError.invalidPageToken(customMessage);
    case 'INVALID_PHONE_NUMBER':
      // Invalid phone number.
      return FirebaseAuthError.invalidPhoneNumber(customMessage);
    case 'INVALID_SERVICE_ACCOUNT':
      // Invalid service account.
      return FirebaseAuthError.invalidServiceAccount(customMessage);
    case 'MISSING_ANDROID_PACKAGE_NAME':
      // Missing Android package name.
      return FirebaseAuthError.missingAndroidPackageName(customMessage);
    case 'MISSING_IOS_BUNDLE_ID':
      // Missing iOS bundle ID.
      return FirebaseAuthError.missingIosBundleId(customMessage);
    case 'MISSING_LOCAL_ID':
      // No localId provided (deleteAccount missing localId).
      return FirebaseAuthError.missingUid(customMessage);
    case 'MISSING_USER_ACCOUNT':
      // Empty user list in uploadAccount.
      return FirebaseAuthError.missingUid(customMessage);
    case 'OPERATION_NOT_ALLOWED':
      // Password auth disabled in console.
      return FirebaseAuthError.operationNotAllowed(customMessage);
    case 'PERMISSION_DENIED':
      // Provided credential has insufficient permissions.
      return FirebaseAuthError.insufficientPermission(customMessage);
    case 'PHONE_NUMBER_EXISTS':
      // Phone number already exists.
      return FirebaseAuthError.phoneNumberAlreadyExists(customMessage);
    case 'PROJECT_NOT_FOUND':
      // Project not found.
      return FirebaseAuthError.projectNotFound(customMessage);
    case 'TOKEN_EXPIRED':
      // Token expired error.
      return FirebaseAuthError.idTokenExpired(customMessage);
    case 'UNAUTHORIZED_DOMAIN':
      // Continue URL provided in ActionCodeSettings has a domain that is not whitelisted.
      return FirebaseAuthError.unauthorizedDomain(customMessage);
    case 'USER_NOT_FOUND':
      // User on which action is to be performed is not found.
      return FirebaseAuthError.userNotFound(customMessage);
    case 'WEAK_PASSWORD':
      // Password provided is too weak.
      return FirebaseAuthError.invalidPassword(customMessage);
  }

  return FirebaseAuthError.internalError(customMessage, rawServerResponse);
}