TF-1115 Implement catch exception for MailboxDataSource

This commit is contained in:
dab246
2022-10-28 11:59:47 +07:00
committed by Dat H. Pham
parent 5746d031b9
commit da90a2b2fc
13 changed files with 92 additions and 37 deletions
@@ -23,12 +23,14 @@ import 'package:tmail_ui_user/features/login/data/local/token_oidc_cache_manager
import 'package:tmail_ui_user/features/mailbox/data/local/mailbox_cache_manager.dart';
import 'package:tmail_ui_user/features/manage_account/data/local/language_cache_manager.dart';
import 'package:tmail_ui_user/features/thread/data/local/email_cache_manager.dart';
import 'package:tmail_ui_user/main/exceptions/cache_exception_thrower.dart';
class LocalBindings extends Bindings {
@override
void dependencies() {
_bindingCaching();
_bindingException();
}
void _bindingCaching() {
@@ -61,4 +63,8 @@ class LocalBindings extends Bindings {
Get.find<AccountCacheClient>(),
));
}
void _bindingException() {
Get.put(CacheExceptionThrower());
}
}
@@ -4,7 +4,7 @@ import 'package:tmail_ui_user/main/exceptions/exception_thrower.dart';
class CacheExceptionThrower extends ExceptionThrower {
@override
void throwException(dynamic exception) {
throw UnknownCacheError(message: exception.toString());
void throwException(dynamic error) {
throw UnknownCacheError(message: error.toString());
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
abstract class ExceptionThrower {
void throwException(dynamic exception);
void throwException(dynamic error);
}
@@ -8,22 +8,22 @@ import 'package:tmail_ui_user/main/exceptions/remote_exception.dart';
class RemoteExceptionThrower extends ExceptionThrower {
@override
void throwException(dynamic exception) {
if (exception is DioError) {
switch (exception.type) {
void throwException(dynamic error) {
if (error is DioError) {
switch (error.type) {
case DioErrorType.connectTimeout:
throw const ConnectError();
default:
if (exception.response?.statusCode == 502) {
if (error.response?.statusCode == 502) {
throw BadGateway();
} else {
throw UnknownError(
code: exception.response?.statusCode,
message: exception.response?.statusMessage);
code: error.response?.statusCode,
message: error.response?.statusMessage);
}
}
} else if (exception is ErrorMethodResponseException) {
final errorResponse = exception.errorResponse as ErrorMethodResponse;
} else if (error is ErrorMethodResponseException) {
final errorResponse = error.errorResponse as ErrorMethodResponse;
if (errorResponse is CannotCalculateChangesMethodResponse) {
throw CannotCalculateChangesMethodResponseException();
} else {
@@ -32,7 +32,7 @@ class RemoteExceptionThrower extends ExceptionThrower {
message: errorResponse.description);
}
} else {
throw UnknownError(message: exception.toString());
throw UnknownError(message: error.toString());
}
}
}