Skip to content

Commit

Permalink
[splash] proper error type checking on login
Browse files Browse the repository at this point in the history
fixes #243. Remember: Don't use `runtimeType` for anything!
  • Loading branch information
dreautall committed Dec 28, 2023
1 parent 238d279 commit 63fd9be
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions lib/pages/splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,31 @@ class _SplashPageState extends State<SplashPage> {
String errorDetails =
"Host: ${context.read<FireflyService>().lastTriedHost}";
final String errorDescription = () {
switch (_loginError.runtimeType) {
case AuthErrorHost _:
case AuthErrorApiKey _:
case AuthErrorNoInstance _:
case AuthErrorVersionInvalid _:
AuthError errorType = _loginError as AuthError;
return errorType.cause;
case AuthErrorStatusCode errorType:
errorDetails += "\n";
errorDetails += S.of(context).errorStatusCode(errorType.code);
return errorType.cause;
case AuthErrorVersionTooLow errorType:
errorDetails += "\n";
errorDetails += S
.of(context)
.errorMinAPIVersion(errorType.requiredVersion.toString());
return errorType.cause;
case HandshakeException _:
showCertButton = true;
return S.of(context).errorInvalidSSLCert;
default:
errorDetails += "\n$_loginError";
return S.of(context).errorUnknown;
if (_loginError is AuthErrorHost ||
_loginError is AuthErrorApiKey ||
_loginError is AuthErrorNoInstance ||
_loginError is AuthErrorVersionInvalid) {
AuthError errorType = _loginError as AuthError;
return errorType.cause;
} else if (_loginError is AuthErrorStatusCode) {
AuthErrorStatusCode errorType = _loginError as AuthErrorStatusCode;
errorDetails += "\n";
errorDetails += S.of(context).errorStatusCode(errorType.code);
return errorType.cause;
} else if (_loginError is AuthErrorVersionTooLow) {
AuthErrorVersionTooLow errorType =
_loginError as AuthErrorVersionTooLow;
errorDetails += "\n";
errorDetails += S
.of(context)
.errorMinAPIVersion(errorType.requiredVersion.toString());
return errorType.cause;
} else if (_loginError is HandshakeException) {
showCertButton = true;
return S.of(context).errorInvalidSSLCert;
}
errorDetails += "\n$_loginError";
return S.of(context).errorUnknown;
}();
page = SizedBox(
width: double.infinity,
Expand Down

0 comments on commit 63fd9be

Please sign in to comment.