Skip to content

Instantly share code, notes, and snippets.

@oalansari82
Created May 27, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oalansari82/241150aa8abf5e538617ca7fada728f9 to your computer and use it in GitHub Desktop.
Save oalansari82/241150aa8abf5e538617ca7fada728f9 to your computer and use it in GitHub Desktop.
Firebase Auth & Storage Error Handling for iOS
// MARK: - Firebase Auth
extension Auth {
//Handle Firebase Auth Errors
static func handleFirebaseAuthErrorWith(errorCode: AuthErrorCode) -> [String] {
switch errorCode {
case .emailAlreadyInUse:
let title = "User Exist"
let message = "The email address provided already exist. Please login using your credentials."
return [title, message]
case .invalidEmail:
let title = "Invalid Email"
let message = "The email address provided is invalid."
return [title, message]
case .userDisabled:
let title = "User Disabled"
let message = "Your account has been disabled."
return [title, message]
case .wrongPassword:
let title = "Wrong Password"
let message = "Please check password and try again."
return [title, message]
case .userNotFound:
let title = "User Not Found"
let message = "There is no user registered with the details you have provided. "
return [title, message]
case .weakPassword:
let title = "Weak Password"
let message = "Please use a more secure password with at least 6 alphanumeric characters."
return [title, message]
case .requiresRecentLogin:
let title = "Recent Login Required"
let message = "You need to login again in order to update sensitive account details."
return [title, message]
default:
let title = "Error"
let message = "\(errorCode)"
return [title, message]
}
}
}
// MARK: - Firebase Storage
extension Storage {
//Handle Firebase Storage Errors
static func handleFirebaseStorageErrorWith(errorCode: StorageErrorCode) -> [String] {
switch errorCode {
case .unknown:
let title = "Uknown Error"
let message = "An unknown error occurred."
return [title, message]
case .objectNotFound:
let title = "Object Not Found"
let message = "No object exists at the desired reference."
return [title, message]
case .bucketNotFound:
let title = "Bucket Not Found"
let message = "No bucket is configured for Cloud Storage."
return [title, message]
case .projectNotFound:
let title = "Project Not Found"
let message = "No project is configured for Cloud Storage."
return [title, message]
case .quotaExceeded:
let title = "Quota Exceeded"
let message = "Quota on your Cloud Storage bucket has been exceeded."
return [title, message]
case .unauthenticated:
let title = "User Unauthenticated"
let message = "User is unauthenticated. Authenticate and try again."
return [title, message]
case .unauthorized:
let title = "User Not Authorized"
let message = "User is not authorized to perform the desired action."
return [title, message]
case .retryLimitExceeded:
let title = "Limit Exceeded"
let message = "The maximum time limit on an operation has been exceeded."
return [title, message]
case .nonMatchingChecksum:
let title = "Non Matching Checksum"
let message = "File on the client does not match the checksum of the file recieved by the server. Try uploading again."
return [title, message]
case .cancelled:
let title = "Cancelled"
let message = "User canceled the operation."
return [title, message]
case .downloadSizeExceeded:
let title = "File Size Exceeded"
let message = "Size of the downloaded file exceeds the amount of memory allocated for the download."
return [title, message]
}
}
func showAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
alert.dismiss(animated: true, completion: nil)
}))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment