From 150e678a730ac28c7012abe0974fcba9f3028b54 Mon Sep 17 00:00:00 2001 From: Dat PHAM HOANG Date: Fri, 3 Mar 2023 12:11:26 +0700 Subject: [PATCH] Add BadCredentialsException --- lib/l10n/intl_messages.arb | 8 +++++++- lib/main/exceptions/remote_exception.dart | 8 ++++++++ lib/main/exceptions/remote_exception_thrower.dart | 4 +++- lib/main/localizations/app_localizations.dart | 4 ++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/l10n/intl_messages.arb b/lib/l10n/intl_messages.arb index 931c394a5..5cb999f2e 100644 --- a/lib/l10n/intl_messages.arb +++ b/lib/l10n/intl_messages.arb @@ -1,5 +1,5 @@ { - "@@last_modified": "2023-03-02T21:08:14.879842", + "@@last_modified": "2023-03-03T11:59:08.917209", "initializing_data": "Initializing data...", "@initializing_data": { "type": "text", @@ -24,6 +24,12 @@ "placeholders_order": [], "placeholders": {} }, + "Bad credentials": "Bad credentials", + "@Bad credentials": { + "type": "text", + "placeholders_order": [], + "placeholders": {} + }, "next": "Next", "@next": { "type": "text", diff --git a/lib/main/exceptions/remote_exception.dart b/lib/main/exceptions/remote_exception.dart index fa7452c93..d75abd488 100644 --- a/lib/main/exceptions/remote_exception.dart +++ b/lib/main/exceptions/remote_exception.dart @@ -6,6 +6,7 @@ import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.da abstract class RemoteException with EquatableMixin implements Exception { static const connectError = 'Connect error'; static const noNetworkError = 'No network error'; + static const badCredentials = 'Bad credentials'; final String? message; final int? code; @@ -13,6 +14,13 @@ abstract class RemoteException with EquatableMixin implements Exception { const RemoteException({this.code, this.message}); } +class BadCredentialsException extends RemoteException { + const BadCredentialsException() : super(message: RemoteException.badCredentials); + + @override + List get props => []; +} + class UnknownError extends RemoteException { const UnknownError({int? code, String? message}) : super(code: code, message: message); diff --git a/lib/main/exceptions/remote_exception_thrower.dart b/lib/main/exceptions/remote_exception_thrower.dart index c8b1470d6..50374ee00 100644 --- a/lib/main/exceptions/remote_exception_thrower.dart +++ b/lib/main/exceptions/remote_exception_thrower.dart @@ -1,5 +1,6 @@ import 'package:core/utils/app_logger.dart'; import 'package:dio/dio.dart'; +import 'package:get/get_connect/http/src/status/http_status.dart'; import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; import 'package:jmap_dart_client/jmap/core/error/method/exception/error_method_response_exception.dart'; import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart'; @@ -15,7 +16,6 @@ class RemoteExceptionThrower extends ExceptionThrower { logError('RemoteExceptionThrower::throwException():error: $error'); final networkConnectionController = getBinding(); if (networkConnectionController != null) { - log('RemoteExceptionThrower::throwException(): CONNECTION: ${networkConnectionController.connectivityResult.value}'); if (!networkConnectionController.isNetworkConnectionAvailable()) { throw const NoNetworkError(); } @@ -28,6 +28,8 @@ class RemoteExceptionThrower extends ExceptionThrower { default: if (error.response?.statusCode == 502) { throw BadGateway(); + } else if (error.response?.statusCode == HttpStatus.unauthorized) { + throw const BadCredentialsException(); } else { throw UnknownError( code: error.response?.statusCode, diff --git a/lib/main/localizations/app_localizations.dart b/lib/main/localizations/app_localizations.dart index ad61ff18d..41bb2acca 100644 --- a/lib/main/localizations/app_localizations.dart +++ b/lib/main/localizations/app_localizations.dart @@ -36,6 +36,10 @@ class AppLocalizations { String get loginInputCredentialMessage { return Intl.message('Enter your credentials to sign in', name: 'loginInputCredentialMessage'); } + + String get badCredentials { + return Intl.message('Bad credentials'); + } String get next { return Intl.message('Next', name: 'next');