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