Skip to content

Commit

Permalink
fix: sentry auth exception (#1387)
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras authored Nov 11, 2024
2 parents d8a057e + bc5ba1c commit 1da2fbf
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 40 deletions.
11 changes: 0 additions & 11 deletions packages/uni_app/lib/model/entities/login_exceptions.dart

This file was deleted.

1 change: 1 addition & 0 deletions packages/uni_app/lib/session/exception.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
enum AuthenticationExceptionType {
internetError,
wrongCredentials,
expiredCredentials,
other,
Expand Down
12 changes: 11 additions & 1 deletion packages/uni_app/lib/session/flows/credentials/request.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:uni/controller/fetchers/faculties_fetcher.dart';
import 'package:uni/session/exception.dart';
Expand Down Expand Up @@ -35,11 +36,20 @@ class CredentialsSessionRequest extends SessionRequest {
'Failed to authenticate user',
AuthenticationExceptionType.expiredCredentials,
);
} else {
} else if (failureReason == LoginFailureReason.internetError) {
throw const AuthenticationException(
'Failed to authenticate user',
AuthenticationExceptionType.internetError,
);
} else if (failureReason == LoginFailureReason.wrongCredentials) {
throw const AuthenticationException(
'Failed to authenticate user',
AuthenticationExceptionType.wrongCredentials,
);
} else {
throw const AuthenticationException(
'Failed to authenticate user',
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class LoginResponse extends SigarraResponse {

enum LoginFailureReason {
serverError,
internetError,
wrongCredentials,
expiredCredentials,
blockedAccount,
Expand Down
71 changes: 43 additions & 28 deletions packages/uni_app/lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/app_links/uni_app_links.dart';
import 'package:uni/controller/networking/url_launcher.dart';
import 'package:uni/generated/l10n.dart';
import 'package:uni/model/entities/login_exceptions.dart';
import 'package:uni/model/providers/startup/session_provider.dart';
import 'package:uni/model/providers/state_providers.dart';
import 'package:uni/session/exception.dart';
import 'package:uni/session/flows/credentials/initiator.dart';
import 'package:uni/session/flows/federated/initiator.dart';
import 'package:uni/utils/constants.dart';
Expand Down Expand Up @@ -99,36 +99,51 @@ class LoginPageViewState extends State<LoginPageView>
_loggingIn = false;
});
}
} catch (err, st) {
} on AuthenticationException catch (err, st) {
setState(() {
_loggingIn = false;
});
if (err is ExpiredCredentialsException) {
_updatePasswordDialog();
} else if (err is InternetStatusException) {
if (mounted) {
unawaited(
ToastMessage.warning(
context,
S.of(context).internet_status_exception,
),
);
}
} else if (err is WrongCredentialsException) {
if (mounted) {
unawaited(
ToastMessage.error(
context,
S.of(context).wrong_credentials_exception,
),
);
}
} else {
Logger().e(err, stackTrace: st);
unawaited(Sentry.captureException(err, stackTrace: st));
if (mounted) {
unawaited(ToastMessage.error(context, S.of(context).failed_login));
}

switch (err.type) {
case AuthenticationExceptionType.expiredCredentials:
_updatePasswordDialog();
case AuthenticationExceptionType.internetError:
if (mounted) {
unawaited(
ToastMessage.warning(
context,
S.of(context).internet_status_exception,
),
);
}
case AuthenticationExceptionType.wrongCredentials:
if (mounted) {
unawaited(
ToastMessage.error(
context,
S.of(context).wrong_credentials_exception,
),
);
}
default:
Logger().e(err, stackTrace: st);
unawaited(Sentry.captureException(err, stackTrace: st));
if (mounted) {
unawaited(
ToastMessage.error(context, S.of(context).failed_login),
);
}
}
}
// Handles other unexpected exceptions
catch (err, st) {
setState(() {
_loggingIn = false;
});
Logger().e(err, stackTrace: st);
unawaited(Sentry.captureException(err, stackTrace: st));
if (mounted) {
unawaited(ToastMessage.error(context, S.of(context).failed_login));
}
}
}
Expand Down

0 comments on commit 1da2fbf

Please sign in to comment.