Professional Documents
Culture Documents
Dio Error
Dio Error
dart';
class DioException {
case DioErrorType.response:
return _handleStatusCode(dioError.response!);
case DioErrorType.other:
if (dioError.message.contains('SocketException')) {
return 'No Internet.';
}else{
return 'Unexpected error occurred.';
}
default:
return 'Something went wrong';
}
}
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;
}
}