TF-1829 Fix app crash upon 401
(cherry picked from commit 8906322f932c4e1edadaf3f1831fc533fddd9a8b)
This commit is contained in:
@@ -121,7 +121,8 @@ abstract class BaseController extends GetxController
|
||||
|
||||
Exception? _performFilterExceptionInError(dynamic error) {
|
||||
logError('BaseController::_performFilterExceptionInError(): $error');
|
||||
if (error is NoNetworkError || error is ConnectError || error is InternalServerError) {
|
||||
if (error is NoNetworkError || error is ConnectionTimeout || error is InternalServerError) {
|
||||
logError('BaseController::_performFilterExceptionInError(): NoNetworkError');
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
_appToast.showToastMessage(
|
||||
currentOverlayContext!,
|
||||
@@ -136,6 +137,7 @@ abstract class BaseController extends GetxController
|
||||
}
|
||||
return error;
|
||||
} else if (error is BadCredentialsException) {
|
||||
logError('BaseController::_performFilterExceptionInError(): BadCredentialsException');
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
_appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
@@ -143,6 +145,15 @@ abstract class BaseController extends GetxController
|
||||
}
|
||||
performInvokeLogoutAction();
|
||||
return error;
|
||||
} else if (error is ConnectionError) {
|
||||
logError('BaseController::_performFilterExceptionInError(): ConnectionError');
|
||||
if (currentOverlayContext != null && currentContext != null) {
|
||||
_appToast.showToastErrorMessage(
|
||||
currentOverlayContext!,
|
||||
AppLocalizations.of(currentContext!).connectionError);
|
||||
}
|
||||
performInvokeLogoutAction();
|
||||
return error;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -306,6 +317,7 @@ abstract class BaseController extends GetxController
|
||||
}
|
||||
|
||||
void performInvokeLogoutAction() {
|
||||
log('BaseController::performInvokeLogoutAction():');
|
||||
if (isAuthenticatedWithOidc) {
|
||||
_logoutOIDCAction();
|
||||
} else {
|
||||
|
||||
@@ -101,6 +101,8 @@ class SessionController extends ReloadableController {
|
||||
errorMessage = AppLocalizations.of(currentContext!).wrongUrlMessage;
|
||||
} else if (sessionException is BadCredentialsException && currentContext != null) {
|
||||
errorMessage = AppLocalizations.of(currentContext!).badCredentials;
|
||||
} else if (sessionException is ConnectionError && currentContext != null) {
|
||||
errorMessage = AppLocalizations.of(currentContext!).connectionError;
|
||||
} else if (sessionException is UnknownError && currentContext != null) {
|
||||
if (sessionException.message != null && sessionException.code != null) {
|
||||
errorMessage = '[${sessionException.code}] ${sessionException.message}';
|
||||
@@ -119,7 +121,7 @@ class SessionController extends ReloadableController {
|
||||
}
|
||||
|
||||
bool _checkUrlError(dynamic sessionException) {
|
||||
return sessionException is ConnectError || sessionException is BadGateway || sessionException is SocketError;
|
||||
return sessionException is ConnectionTimeout || sessionException is BadGateway || sessionException is SocketError;
|
||||
}
|
||||
|
||||
void _goToMailboxDashBoard(Session session) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"@@last_modified": "2023-06-09T22:51:52.101985",
|
||||
"@@last_modified": "2023-06-28T15:42:36.189236",
|
||||
"initializing_data": "Initializing data...",
|
||||
"@initializing_data": {
|
||||
"type": "text",
|
||||
@@ -2917,5 +2917,11 @@
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
},
|
||||
"Connection error": "Connection error",
|
||||
"@Connection error": {
|
||||
"type": "text",
|
||||
"placeholders_order": [],
|
||||
"placeholders": {}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import 'package:jmap_dart_client/jmap/core/error/error_type.dart';
|
||||
import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart';
|
||||
|
||||
abstract class RemoteException with EquatableMixin implements Exception {
|
||||
static const connectError = 'Connect error';
|
||||
static const connectionTimeout = 'Connection Timeout';
|
||||
static const connectionError = 'Connection error';
|
||||
static const internalServerError = 'Internal Server Error';
|
||||
static const noNetworkError = 'No network error';
|
||||
static const badCredentials = 'Bad credentials';
|
||||
@@ -27,28 +28,35 @@ class UnknownError extends RemoteException {
|
||||
const UnknownError({int? code, String? message}) : super(code: code, message: message);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
|
||||
class ConnectError extends RemoteException {
|
||||
const ConnectError() : super(message: RemoteException.connectError);
|
||||
class ConnectionError extends RemoteException {
|
||||
const ConnectionError({String? message}) : super(message: message ?? RemoteException.connectionError);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
|
||||
class ConnectionTimeout extends RemoteException {
|
||||
const ConnectionTimeout({String? message}) : super(message: message ?? RemoteException.connectionTimeout);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
|
||||
class SocketError extends RemoteException {
|
||||
const SocketError() : super(message: RemoteException.socketException);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
|
||||
class InternalServerError extends RemoteException {
|
||||
const InternalServerError() : super(message: RemoteException.internalServerError);
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
|
||||
class MethodLevelErrors extends RemoteException {
|
||||
@@ -60,7 +68,7 @@ class MethodLevelErrors extends RemoteException {
|
||||
) : super(message: message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [type, message];
|
||||
List<Object?> get props => [type, code, message];
|
||||
}
|
||||
|
||||
class CannotCalculateChangesMethodResponseException extends MethodLevelErrors {
|
||||
@@ -71,5 +79,5 @@ class NoNetworkError extends RemoteException {
|
||||
const NoNetworkError() : super(message: RemoteException.noNetworkError);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
List<Object?> get props => [code, message];
|
||||
}
|
||||
@@ -25,7 +25,9 @@ class RemoteExceptionThrower extends ExceptionThrower {
|
||||
logError('RemoteExceptionThrower::throwException():type: ${error.type} | response: ${error.response} | error: ${error.error}');
|
||||
switch (error.type) {
|
||||
case DioErrorType.connectionTimeout:
|
||||
throw const ConnectError();
|
||||
throw ConnectionTimeout(message: error.message);
|
||||
case DioErrorType.connectionError:
|
||||
throw ConnectionError(message: error.message);
|
||||
default:
|
||||
if (error.response?.statusCode == HttpStatus.internalServerError) {
|
||||
throw const InternalServerError();
|
||||
|
||||
@@ -3007,4 +3007,8 @@ class AppLocalizations {
|
||||
'Messages have been resent',
|
||||
name: 'messagesHaveBeenResent');
|
||||
}
|
||||
|
||||
String get connectionError {
|
||||
return Intl.message('Connection error');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user