Created
May 27, 2020 14:22
-
-
Save haroonkhan9426/2cb2c43d6662bdd6469b9e864bcadc2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AuthExceptionHandler { | |
static handleException(e) { | |
print(e.code); | |
var status; | |
switch (e.code) { | |
case "ERROR_INVALID_EMAIL": | |
status = AuthResultStatus.invalidEmail; | |
break; | |
case "ERROR_WRONG_PASSWORD": | |
status = AuthResultStatus.wrongPassword; | |
break; | |
case "ERROR_USER_NOT_FOUND": | |
status = AuthResultStatus.userNotFound; | |
break; | |
case "ERROR_USER_DISABLED": | |
status = AuthResultStatus.userDisabled; | |
break; | |
case "ERROR_TOO_MANY_REQUESTS": | |
status = AuthResultStatus.tooManyRequests; | |
break; | |
case "ERROR_OPERATION_NOT_ALLOWED": | |
status = AuthResultStatus.operationNotAllowed; | |
break; | |
case "ERROR_EMAIL_ALREADY_IN_USE": | |
status = AuthResultStatus.emailAlreadyExists; | |
break; | |
default: | |
status = AuthResultStatus.undefined; | |
} | |
return status; | |
} | |
/// | |
/// Accepts AuthExceptionHandler.errorType | |
/// | |
static generateExceptionMessage(exceptionCode) { | |
String errorMessage; | |
switch (exceptionCode) { | |
case AuthResultStatus.invalidEmail: | |
errorMessage = "Your email address appears to be malformed."; | |
break; | |
case AuthResultStatus.wrongPassword: | |
errorMessage = "Your password is wrong."; | |
break; | |
case AuthResultStatus.userNotFound: | |
errorMessage = "User with this email doesn't exist."; | |
break; | |
case AuthResultStatus.userDisabled: | |
errorMessage = "User with this email has been disabled."; | |
break; | |
case AuthResultStatus.tooManyRequests: | |
errorMessage = "Too many requests. Try again later."; | |
break; | |
case AuthResultStatus.operationNotAllowed: | |
errorMessage = "Signing in with Email and Password is not enabled."; | |
break; | |
case AuthResultStatus.emailAlreadyExists: | |
errorMessage = | |
"The email has already been registered. Please login or reset your password."; | |
break; | |
default: | |
errorMessage = "An undefined Error happened."; | |
} | |
return errorMessage; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment