Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sentry auth exception #1387

Merged
merged 5 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 additions & 1 deletion packages/uni_app/lib/session/flows/credentials/request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:uni/controller/fetchers/faculties_fetcher.dart';
import 'package:uni/session/exception.dart';
import 'package:uni/session/flows/base/request.dart';
Expand Down Expand Up @@ -35,11 +37,21 @@ 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 {
unawaited(Sentry.captureException(failureReason));
peucastro marked this conversation as resolved.
Show resolved Hide resolved
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
73 changes: 1 addition & 72 deletions packages/uni_app/lib/view/login/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import 'package:logger/logger.dart';
import 'package:provider/provider.dart';
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/flows/credentials/initiator.dart';
Expand Down Expand Up @@ -99,37 +97,10 @@ class LoginPageViewState extends State<LoginPageView>
_loggingIn = false;
});
}
} catch (err, st) {
} catch (err) {
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));
}
}
peucastro marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down Expand Up @@ -364,46 +335,4 @@ class LoginPageViewState extends State<LoginPageView>
},
);
}

void _updatePasswordDialog() {
thePeras marked this conversation as resolved.
Show resolved Hide resolved
showDialog<void>(
context: context,
builder: (context) {
return AlertDialog(
title: Text(S.of(context).expired_password),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
S.of(context).pass_change_request,
textAlign: TextAlign.start,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 20),
Align(
alignment: Alignment.centerLeft,
child: Text(
S.of(context).change_prompt,
textAlign: TextAlign.start,
),
),
],
),
actions: [
TextButton(
child: Text(S.of(context).cancel),
onPressed: () {
Navigator.of(context).pop();
},
),
ElevatedButton(
child: Text(S.of(context).change),
onPressed: () =>
launchUrlWithToast(context, 'https://self-id.up.pt/password'),
),
],
);
},
);
}
}