diff --git a/core/lib/core.dart b/core/lib/core.dart index e69afcb43..fa8bc9225 100644 --- a/core/lib/core.dart +++ b/core/lib/core.dart @@ -25,6 +25,7 @@ export 'domain/exceptions/download_file_exception.dart'; export 'data/extensions/options_extensions.dart'; export 'domain/exceptions/web_session_exception.dart'; export 'domain/exceptions/platform_exception.dart'; +export 'domain/exceptions/app_base_exception.dart'; // Utils export 'presentation/utils/theme_utils.dart'; diff --git a/core/lib/domain/exceptions/address_exception.dart b/core/lib/domain/exceptions/address_exception.dart index 51889bbf7..d2433dca3 100644 --- a/core/lib/domain/exceptions/address_exception.dart +++ b/core/lib/domain/exceptions/address_exception.dart @@ -1,13 +1,12 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:equatable/equatable.dart'; -class AddressException with EquatableMixin implements Exception { - final String message; - - AddressException(this.message); +class AddressException extends AppBaseException with EquatableMixin { + const AddressException(super.message); @override - String toString() => message; + String get exceptionName => 'AddressException'; @override - List get props => [message]; + List get props => [message, exceptionName]; } diff --git a/core/lib/domain/exceptions/app_base_exception.dart b/core/lib/domain/exceptions/app_base_exception.dart new file mode 100644 index 000000000..0436e18ac --- /dev/null +++ b/core/lib/domain/exceptions/app_base_exception.dart @@ -0,0 +1,15 @@ +abstract class AppBaseException implements Exception { + final String? message; + + const AppBaseException([this.message]); + + @override + String toString() { + if (message != null && message!.isNotEmpty) { + return '$exceptionName: $message'; + } + return exceptionName; + } + + String get exceptionName; +} diff --git a/core/lib/domain/exceptions/download_file_exception.dart b/core/lib/domain/exceptions/download_file_exception.dart index 8eedec41f..6f6cc4963 100644 --- a/core/lib/domain/exceptions/download_file_exception.dart +++ b/core/lib/domain/exceptions/download_file_exception.dart @@ -1,31 +1,32 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:equatable/equatable.dart'; -abstract class DownloadFileException with EquatableMixin implements Exception { - final String message; - - DownloadFileException(this.message); +abstract class DownloadFileException extends AppBaseException + with EquatableMixin { + const DownloadFileException(super.message); @override - String toString() => message; - - @override - List get props => [message]; + List get props => [message, exceptionName]; } class CommonDownloadFileException extends DownloadFileException { - CommonDownloadFileException(message) : super(message); + const CommonDownloadFileException(super.message); @override - List get props => [message]; + String get exceptionName => 'CommonDownloadFileException'; } class CancelDownloadFileException extends DownloadFileException { - CancelDownloadFileException(cancelMessage) : super(cancelMessage); + const CancelDownloadFileException(super.message); @override - List get props => [message]; + String get exceptionName => 'CancelDownloadFileException'; } class DeviceNotSupportedException extends DownloadFileException { - DeviceNotSupportedException() : super('This device is not supported, please try on Android or iOS'); -} \ No newline at end of file + const DeviceNotSupportedException() + : super('This device is not supported, please try on Android or iOS'); + + @override + String get exceptionName => 'DeviceNotSupportedException'; +} diff --git a/core/lib/domain/exceptions/file_exception.dart b/core/lib/domain/exceptions/file_exception.dart index 16e8980a8..3ba770ea9 100644 --- a/core/lib/domain/exceptions/file_exception.dart +++ b/core/lib/domain/exceptions/file_exception.dart @@ -1,21 +1,23 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:equatable/equatable.dart'; -abstract class FileException with EquatableMixin implements Exception { - final String message; - - FileException(this.message); +abstract class FileException extends AppBaseException with EquatableMixin { + const FileException(super.message); @override - String toString() => message; - - @override - List get props => [message]; + List get props => [message, exceptionName]; } class NotFoundFileInFolderException extends FileException { NotFoundFileInFolderException() : super('No files found in the folder'); + + @override + String get exceptionName => 'NotFoundFileInFolderException'; } class UserCancelShareFileException extends FileException { UserCancelShareFileException() : super('User cancel share file'); -} \ No newline at end of file + + @override + String get exceptionName => 'UserCancelShareFileException'; +} diff --git a/core/lib/domain/exceptions/platform_exception.dart b/core/lib/domain/exceptions/platform_exception.dart index 9569df122..962ee74cb 100644 --- a/core/lib/domain/exceptions/platform_exception.dart +++ b/core/lib/domain/exceptions/platform_exception.dart @@ -1,14 +1,19 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:equatable/equatable.dart'; -class PlatformException with EquatableMixin implements Exception { - final String message; - - PlatformException(this.message); +class PlatformException extends AppBaseException with EquatableMixin { + const PlatformException(super.message); @override - List get props => [message]; + String get exceptionName => 'PlatformException'; + + @override + List get props => [message, exceptionName]; } class NoSupportPlatformException extends PlatformException { - NoSupportPlatformException() : super('This platform is not supported'); -} \ No newline at end of file + const NoSupportPlatformException() : super('This platform is not supported'); + + @override + String get exceptionName => 'NoSupportPlatformException'; +} diff --git a/core/lib/domain/exceptions/string_exception.dart b/core/lib/domain/exceptions/string_exception.dart index e3d8d10ea..9ddd383f1 100644 --- a/core/lib/domain/exceptions/string_exception.dart +++ b/core/lib/domain/exceptions/string_exception.dart @@ -1,7 +1,15 @@ -class UnsupportedCharsetException implements Exception { - const UnsupportedCharsetException(); +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class UnsupportedCharsetException extends AppBaseException { + const UnsupportedCharsetException([super.message]); + + @override + String get exceptionName => 'UnsupportedCharsetException'; } -class NullCharsetException implements Exception { - const NullCharsetException(); -} \ No newline at end of file +class NullCharsetException extends AppBaseException { + const NullCharsetException([super.message]); + + @override + String get exceptionName => 'NullCharsetException'; +} diff --git a/core/lib/domain/exceptions/web_session_exception.dart b/core/lib/domain/exceptions/web_session_exception.dart index a18f482c9..75579036b 100644 --- a/core/lib/domain/exceptions/web_session_exception.dart +++ b/core/lib/domain/exceptions/web_session_exception.dart @@ -1,28 +1,44 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:equatable/equatable.dart'; -class NotFoundInWebSessionException with EquatableMixin implements Exception { - final String? errorMessage; - - NotFoundInWebSessionException({this.errorMessage}); +class NotFoundInWebSessionException extends AppBaseException + with EquatableMixin { + const NotFoundInWebSessionException({String? errorMessage}) + : super(errorMessage); @override - List get props => []; -} - -class NotMatchInWebSessionException with EquatableMixin implements Exception { - const NotMatchInWebSessionException(); + String get exceptionName => 'NotFoundInWebSessionException'; @override - List get props => []; + List get props => [message, exceptionName]; } -class SaveToWebSessionFailException with EquatableMixin implements Exception { - final String? errorMessage; - - SaveToWebSessionFailException({this.errorMessage}); +class NotMatchInWebSessionException extends AppBaseException + with EquatableMixin { + const NotMatchInWebSessionException() : super('Session data does not match'); @override - List get props => []; + String get exceptionName => 'NotMatchInWebSessionException'; + + @override + List get props => [message, exceptionName]; } -class CannotOpenNewWindowException implements Exception {} +class SaveToWebSessionFailException extends AppBaseException + with EquatableMixin { + const SaveToWebSessionFailException({String? errorMessage}) + : super(errorMessage); + + @override + String get exceptionName => 'SaveToWebSessionFailException'; + + @override + List get props => [message, exceptionName]; +} + +class CannotOpenNewWindowException extends AppBaseException { + const CannotOpenNewWindowException([super.message]); + + @override + String get exceptionName => 'CannotOpenNewWindowException'; +} diff --git a/core/lib/utils/file_utils.dart b/core/lib/utils/file_utils.dart index ec84c1234..3681943fc 100644 --- a/core/lib/utils/file_utils.dart +++ b/core/lib/utils/file_utils.dart @@ -39,7 +39,7 @@ class FileUtils { return fileDirectory; } else { - throw DeviceNotSupportedException(); + throw const DeviceNotSupportedException(); } } diff --git a/core/lib/utils/logger/log_tracking.dart b/core/lib/utils/logger/log_tracking.dart index f6a64009f..2f3b5faa6 100644 --- a/core/lib/utils/logger/log_tracking.dart +++ b/core/lib/utils/logger/log_tracking.dart @@ -130,7 +130,7 @@ class LogTracking { return fileDirectory; } else { - throw DeviceNotSupportedException(); + throw const DeviceNotSupportedException(); } } diff --git a/core/lib/utils/mail/mail_address.dart b/core/lib/utils/mail/mail_address.dart index 59ab41c3d..e313dab1c 100644 --- a/core/lib/utils/mail/mail_address.dart +++ b/core/lib/utils/mail/mail_address.dart @@ -40,7 +40,7 @@ class MailAddress with EquatableMixin { address = address.trim(); if (address.isEmpty) { - throw AddressException('Addresses should not be empty'); + throw const AddressException('Addresses should not be empty'); } int pos = 0; @@ -88,7 +88,7 @@ class MailAddress with EquatableMixin { if (postChar == '.') { var lastChar = address[pos - 1]; if (lastChar == '@' || lastChar == '.') { - throw AddressException('Subdomain expected before "." or duplicate "." in "address"'); + throw const AddressException('Subdomain expected before "." or duplicate "." in "address"'); } domainSB.write('.'); pos++; @@ -113,7 +113,7 @@ class MailAddress with EquatableMixin { if (localPart.startsWith('.') || localPart.endsWith('.') || _haveDoubleDot(localPart)) { - throw AddressException('Addresses cannot start end with "." or contain two consecutive dots'); + throw const AddressException('Addresses cannot start end with "." or contain two consecutive dots'); } domain = _createDomain(domainSB.toString()); @@ -409,7 +409,7 @@ class MailAddress with EquatableMixin { lastCharDot = false; } else if (postChar == '.') { if (pos == 0) { - throw AddressException('Local part must not start with a "."'); + throw const AddressException('Local part must not start with a "."'); } lpSB.write('.'); pos++; @@ -530,14 +530,14 @@ class MailAddress with EquatableMixin { String localPartDetails = localPartDetailsSB.toString(); if (localPartDetails.isEmpty || localPartDetails.trim().isEmpty) { - throw AddressException("target mailbox name should not be empty"); + throw const AddressException("target mailbox name should not be empty"); } if (localPartDetails.startsWith('#')) { - throw AddressException("target mailbox name should not start with #"); + throw const AddressException("target mailbox name should not start with #"); } final forbiddenChars = RegExp(r'[*\r\n]'); if (forbiddenChars.hasMatch(localPartDetails)) { - throw AddressException("target mailbox name should not contain special characters"); + throw const AddressException("target mailbox name should not contain special characters"); } localPartSB.write(localPartDetails); diff --git a/integration_test/exceptions/mailbox/null_inbox_unread_count_exception.dart b/integration_test/exceptions/mailbox/null_inbox_unread_count_exception.dart index da6dfa130..4e266f2e5 100644 --- a/integration_test/exceptions/mailbox/null_inbox_unread_count_exception.dart +++ b/integration_test/exceptions/mailbox/null_inbox_unread_count_exception.dart @@ -1 +1,8 @@ -class NullInboxUnreadCountException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class NullInboxUnreadCountException extends AppBaseException { + const NullInboxUnreadCountException([super.message]); + + @override + String get exceptionName => 'NullInboxUnreadCountException'; +} diff --git a/integration_test/exceptions/mailbox/null_quota_exception.dart b/integration_test/exceptions/mailbox/null_quota_exception.dart index b0374633d..fc83154be 100644 --- a/integration_test/exceptions/mailbox/null_quota_exception.dart +++ b/integration_test/exceptions/mailbox/null_quota_exception.dart @@ -1 +1,8 @@ -class NullQuotaException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class NullQuotaException extends AppBaseException { + NullQuotaException([super.message]); + + @override + String get exceptionName => 'NullQuotaException'; +} diff --git a/integration_test/robots/mailbox_menu_robot.dart b/integration_test/robots/mailbox_menu_robot.dart index 2a1330dde..f43bf7d65 100644 --- a/integration_test/robots/mailbox_menu_robot.dart +++ b/integration_test/robots/mailbox_menu_robot.dart @@ -97,7 +97,7 @@ class MailboxMenuRobot extends CoreRobot { .toInt(); if (inboxCount == null) { - throw NullInboxUnreadCountException(); + throw const NullInboxUnreadCountException(); } return inboxCount; diff --git a/lib/features/base/base_controller.dart b/lib/features/base/base_controller.dart index 16b9dddd6..581605f2a 100644 --- a/lib/features/base/base_controller.dart +++ b/lib/features/base/base_controller.dart @@ -168,7 +168,7 @@ abstract class BaseController extends GetxController } else if (PlatformInfo.isMobile) { handleUrgentExceptionOnMobile(failure: failure, exception: exception); } else { - throw NoSupportPlatformException(); + throw const NoSupportPlatformException(); } } diff --git a/lib/features/caching/exceptions/local_storage_exception.dart b/lib/features/caching/exceptions/local_storage_exception.dart index 0c8c81cb9..e901206a9 100644 --- a/lib/features/caching/exceptions/local_storage_exception.dart +++ b/lib/features/caching/exceptions/local_storage_exception.dart @@ -1 +1,8 @@ -class NotFoundDataWithThisKeyException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class NotFoundDataWithThisKeyException extends AppBaseException { + NotFoundDataWithThisKeyException([super.message]); + + @override + String get exceptionName => 'NotFoundDataWithThisKeyException'; +} diff --git a/lib/features/composer/domain/exceptions/compose_email_exception.dart b/lib/features/composer/domain/exceptions/compose_email_exception.dart index b0d29ed9d..cae7c74e4 100644 --- a/lib/features/composer/domain/exceptions/compose_email_exception.dart +++ b/lib/features/composer/domain/exceptions/compose_email_exception.dart @@ -1,3 +1,15 @@ -class SendingEmailCanceledException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class SavingEmailToDraftsCanceledException implements Exception {} \ No newline at end of file +class SendingEmailCanceledException extends AppBaseException { + SendingEmailCanceledException([super.message]); + + @override + String get exceptionName => 'SendingEmailCanceledException'; +} + +class SavingEmailToDraftsCanceledException extends AppBaseException { + SavingEmailToDraftsCanceledException([super.message]); + + @override + String get exceptionName => 'SavingEmailToDraftsCanceledException'; +} diff --git a/lib/features/composer/domain/exceptions/set_method_exception.dart b/lib/features/composer/domain/exceptions/set_method_exception.dart index 174a75c7a..4bb0e42e6 100644 --- a/lib/features/composer/domain/exceptions/set_method_exception.dart +++ b/lib/features/composer/domain/exceptions/set_method_exception.dart @@ -1,10 +1,12 @@ - import 'package:jmap_dart_client/jmap/core/error/set_error.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -class SetMethodException implements Exception { - +class SetMethodException extends AppBaseException { final Map mapErrors; - SetMethodException(this.mapErrors); -} \ No newline at end of file + SetMethodException(this.mapErrors) : super('Errors: $mapErrors'); + + @override + String get exceptionName => 'SetMethodException'; +} diff --git a/lib/features/download/domain/exceptions/download_attachment_exceptions.dart b/lib/features/download/domain/exceptions/download_attachment_exceptions.dart index 2a9c3df03..0b5218881 100644 --- a/lib/features/download/domain/exceptions/download_attachment_exceptions.dart +++ b/lib/features/download/domain/exceptions/download_attachment_exceptions.dart @@ -1,5 +1,22 @@ -class DownloadAttachmentInteractorIsNull implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class CapabilityDownloadAllNotSupportedException implements Exception {} +class DownloadAttachmentInteractorIsNull extends AppBaseException { + DownloadAttachmentInteractorIsNull([super.message]); -class DownloadUrlIsNullException implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'DownloadAttachmentInteractorIsNull'; +} + +class CapabilityDownloadAllNotSupportedException extends AppBaseException { + CapabilityDownloadAllNotSupportedException([super.message]); + + @override + String get exceptionName => 'CapabilityDownloadAllNotSupportedException'; +} + +class DownloadUrlIsNullException extends AppBaseException { + DownloadUrlIsNullException([super.message]); + + @override + String get exceptionName => 'DownloadUrlIsNullException'; +} diff --git a/lib/features/download/presentation/extensions/preview_attachment_download_controller_extension.dart b/lib/features/download/presentation/extensions/preview_attachment_download_controller_extension.dart index ec97759d1..1dc4af0ba 100644 --- a/lib/features/download/presentation/extensions/preview_attachment_download_controller_extension.dart +++ b/lib/features/download/presentation/extensions/preview_attachment_download_controller_extension.dart @@ -536,7 +536,7 @@ extension PreviewAttachmentDownloadControllerExtension on DownloadController { if (!isOpen) { toastManager.showMessageFailure( - PreviewEmailFromEmlFileFailure(CannotOpenNewWindowException()), + PreviewEmailFromEmlFileFailure(const CannotOpenNewWindowException()), ); } } else if (PlatformInfo.isMobile) { diff --git a/lib/features/email/domain/exceptions/calendar_event_exceptions.dart b/lib/features/email/domain/exceptions/calendar_event_exceptions.dart index a85d1c22e..aafb4d856 100644 --- a/lib/features/email/domain/exceptions/calendar_event_exceptions.dart +++ b/lib/features/email/domain/exceptions/calendar_event_exceptions.dart @@ -1,19 +1,48 @@ - import 'package:jmap_dart_client/jmap/core/error/set_error.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundCalendarEventException implements Exception {} +class NotFoundCalendarEventException extends AppBaseException { + NotFoundCalendarEventException([super.message]); -class NotParsableCalendarEventException implements Exception {} + @override + String get exceptionName => 'NotFoundCalendarEventException'; +} -class NotAcceptableCalendarEventException implements Exception {} +class NotParsableCalendarEventException extends AppBaseException { + NotParsableCalendarEventException([super.message]); -class NotMaybeableCalendarEventException implements Exception {} + @override + String get exceptionName => 'NotParsableCalendarEventException'; +} -class NotRejectableCalendarEventException implements Exception {} +class NotAcceptableCalendarEventException extends AppBaseException { + NotAcceptableCalendarEventException([super.message]); -class CannotReplyCalendarEventException implements Exception { + @override + String get exceptionName => 'NotAcceptableCalendarEventException'; +} + +class NotMaybeableCalendarEventException extends AppBaseException { + NotMaybeableCalendarEventException([super.message]); + + @override + String get exceptionName => 'NotMaybeableCalendarEventException'; +} + +class NotRejectableCalendarEventException extends AppBaseException { + NotRejectableCalendarEventException([super.message]); + + @override + String get exceptionName => 'NotRejectableCalendarEventException'; +} + +class CannotReplyCalendarEventException extends AppBaseException { final Map? mapErrors; - CannotReplyCalendarEventException({this.mapErrors}); -} \ No newline at end of file + CannotReplyCalendarEventException({this.mapErrors}) + : super(mapErrors != null ? 'Errors: $mapErrors' : null); + + @override + String get exceptionName => 'CannotReplyCalendarEventException'; +} diff --git a/lib/features/email/domain/exceptions/email_cache_exceptions.dart b/lib/features/email/domain/exceptions/email_cache_exceptions.dart index 5e2a9e9bd..b9224adc2 100644 --- a/lib/features/email/domain/exceptions/email_cache_exceptions.dart +++ b/lib/features/email/domain/exceptions/email_cache_exceptions.dart @@ -1,8 +1,29 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundStoredOpenedEmailException implements Exception {} +class NotFoundStoredOpenedEmailException extends AppBaseException { + NotFoundStoredOpenedEmailException([super.message]); -class NotFoundStoredNewEmailException implements Exception {} + @override + String get exceptionName => 'NotFoundStoredOpenedEmailException'; +} -class NotFoundStoredEmailException implements Exception {} +class NotFoundStoredNewEmailException extends AppBaseException { + NotFoundStoredNewEmailException([super.message]); -class OpenedEmailAlreadyStoredException implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'NotFoundStoredNewEmailException'; +} + +class NotFoundStoredEmailException extends AppBaseException { + NotFoundStoredEmailException([super.message]); + + @override + String get exceptionName => 'NotFoundStoredEmailException'; +} + +class OpenedEmailAlreadyStoredException extends AppBaseException { + OpenedEmailAlreadyStoredException([super.message]); + + @override + String get exceptionName => 'OpenedEmailAlreadyStoredException'; +} diff --git a/lib/features/email/domain/exceptions/email_exceptions.dart b/lib/features/email/domain/exceptions/email_exceptions.dart index 02fcd7ad2..8fd2fdec9 100644 --- a/lib/features/email/domain/exceptions/email_exceptions.dart +++ b/lib/features/email/domain/exceptions/email_exceptions.dart @@ -1,27 +1,70 @@ import 'package:jmap_dart_client/jmap/core/id.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundEmailException implements Exception {} +class NotFoundEmailException extends AppBaseException { + NotFoundEmailException([super.message]); -class NotFoundEmailContentException implements Exception {} + @override + String get exceptionName => 'NotFoundEmailException'; +} -class EmptyEmailContentException implements Exception {} +class NotFoundEmailContentException extends AppBaseException { + NotFoundEmailContentException([super.message]); -class NotFoundEmailRecoveryActionException implements Exception {} + @override + String get exceptionName => 'NotFoundEmailContentException'; +} -class NotFoundEmailBlobIdException implements Exception {} +class EmptyEmailContentException extends AppBaseException { + EmptyEmailContentException([super.message]); -class CannotCreateEmailObjectException implements Exception {} + @override + String get exceptionName => 'EmptyEmailContentException'; +} -class NotFoundBlobIdException implements Exception { +class NotFoundEmailRecoveryActionException extends AppBaseException { + NotFoundEmailRecoveryActionException([super.message]); + + @override + String get exceptionName => 'NotFoundEmailRecoveryActionException'; +} + +class NotFoundEmailBlobIdException extends AppBaseException { + NotFoundEmailBlobIdException([super.message]); + + @override + String get exceptionName => 'NotFoundEmailBlobIdException'; +} + +class CannotCreateEmailObjectException extends AppBaseException { + CannotCreateEmailObjectException([super.message]); + + @override + String get exceptionName => 'CannotCreateEmailObjectException'; +} + +class NotFoundBlobIdException extends AppBaseException { final List ids; - NotFoundBlobIdException(this.ids); + NotFoundBlobIdException(this.ids) : super('Blob IDs: $ids'); + + @override + String get exceptionName => 'NotFoundBlobIdException'; } -class NotParsableBlobIdToEmailException implements Exception { +class NotParsableBlobIdToEmailException extends AppBaseException { final List? ids; - NotParsableBlobIdToEmailException({this.ids}); + NotParsableBlobIdToEmailException({this.ids}) + : super(ids != null ? 'Blob IDs: $ids' : null); + + @override + String get exceptionName => 'NotParsableBlobIdToEmailException'; } -class EmailIdsSuccessIsEmptyException implements Exception {} \ No newline at end of file +class EmailIdsSuccessIsEmptyException extends AppBaseException { + EmailIdsSuccessIsEmptyException([super.message]); + + @override + String get exceptionName => 'EmailIdsSuccessIsEmptyException'; +} diff --git a/lib/features/home/data/exceptions/session_exceptions.dart b/lib/features/home/data/exceptions/session_exceptions.dart index 2e5b49b40..00590d04c 100644 --- a/lib/features/home/data/exceptions/session_exceptions.dart +++ b/lib/features/home/data/exceptions/session_exceptions.dart @@ -1,8 +1,29 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundSessionException implements Exception {} +class NotFoundSessionException extends AppBaseException { + NotFoundSessionException([super.message]); -class NotFoundAccountIdException implements Exception {} + @override + String get exceptionName => 'NotFoundSessionException'; +} -class NotFoundContextException implements Exception {} +class NotFoundAccountIdException extends AppBaseException { + NotFoundAccountIdException([super.message]); -class ParametersIsNullException implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'NotFoundAccountIdException'; +} + +class NotFoundContextException extends AppBaseException { + NotFoundContextException([super.message]); + + @override + String get exceptionName => 'NotFoundContextException'; +} + +class ParametersIsNullException extends AppBaseException { + ParametersIsNullException([super.message]); + + @override + String get exceptionName => 'ParametersIsNullException'; +} diff --git a/lib/features/identity_creator/data/datasource_impl/local_identity_creator_data_source_impl.dart b/lib/features/identity_creator/data/datasource_impl/local_identity_creator_data_source_impl.dart index 78a306dd8..0c8ff8f1c 100644 --- a/lib/features/identity_creator/data/datasource_impl/local_identity_creator_data_source_impl.dart +++ b/lib/features/identity_creator/data/datasource_impl/local_identity_creator_data_source_impl.dart @@ -46,7 +46,7 @@ class LocalIdentityCreatorDataSourceImpl implements IdentityCreatorDataSource { if (result != null) { return IdentityCacheModel.fromJson(jsonDecode(result.value)); } else { - throw NotFoundInWebSessionException(); + throw const NotFoundInWebSessionException(); } }).catchError(_exceptionThrower.throwException); } diff --git a/lib/features/labels/domain/exceptions/label_exceptions.dart b/lib/features/labels/domain/exceptions/label_exceptions.dart index cffa93769..1770d432d 100644 --- a/lib/features/labels/domain/exceptions/label_exceptions.dart +++ b/lib/features/labels/domain/exceptions/label_exceptions.dart @@ -1,9 +1,15 @@ -class LabelKeywordIsNull implements Exception { +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class LabelKeywordIsNull extends AppBaseException { + LabelKeywordIsNull([super.message = 'Label keyword is null']); + @override - String toString() => 'Label keyword is null'; + String get exceptionName => 'LabelKeywordIsNull'; } -class LabelIdIsNull implements Exception { +class LabelIdIsNull extends AppBaseException { + LabelIdIsNull([super.message = 'Label id is null']); + @override - String toString() => 'Label id is null'; + String get exceptionName => 'LabelIdIsNull'; } diff --git a/lib/features/labels/presentation/extensions/handle_label_action_type_extension.dart b/lib/features/labels/presentation/extensions/handle_label_action_type_extension.dart index 2ff5634eb..eb620daa9 100644 --- a/lib/features/labels/presentation/extensions/handle_label_action_type_extension.dart +++ b/lib/features/labels/presentation/extensions/handle_label_action_type_extension.dart @@ -86,7 +86,7 @@ extension HandleLabelActionTypeExtension on LabelController { ); } else if (editLabelInteractor == null) { consumeState( - Stream.value(Left(EditLabelFailure(InteractorNotInitialized()))), + Stream.value(Left(EditLabelFailure(const InteractorNotInitialized()))), ); } else { final labelId = selectedLabel.id; @@ -159,7 +159,7 @@ extension HandleLabelActionTypeExtension on LabelController { } else if (deleteALabelInteractor == null) { emitFailure( controller: this, - failure: DeleteALabelFailure(InteractorNotInitialized()), + failure: DeleteALabelFailure(const InteractorNotInitialized()), ); } else { consumeState(deleteALabelInteractor!.execute(accountId, label)); diff --git a/lib/features/labels/presentation/label_controller.dart b/lib/features/labels/presentation/label_controller.dart index dd1c7a4a0..6914b87f4 100644 --- a/lib/features/labels/presentation/label_controller.dart +++ b/lib/features/labels/presentation/label_controller.dart @@ -146,7 +146,7 @@ class LabelController extends BaseController with LabelContextMenuMixin { log('LabelController::_createNewLabel:Label: $label'); if (_createNewLabelInteractor == null) { consumeState( - Stream.value(Left(CreateNewLabelFailure(InteractorNotInitialized()))), + Stream.value(Left(CreateNewLabelFailure(const InteractorNotInitialized()))), ); } else { consumeState(_createNewLabelInteractor!.execute(accountId, label)); diff --git a/lib/features/login/data/network/oidc_error.dart b/lib/features/login/data/network/oidc_error.dart index bd9f1a6af..de1c9507f 100644 --- a/lib/features/login/data/network/oidc_error.dart +++ b/lib/features/login/data/network/oidc_error.dart @@ -1,9 +1,36 @@ -class CanNotFoundOIDCAuthority implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class CanNotFoundOIDCLinks implements Exception {} +class CanNotFoundOIDCAuthority extends AppBaseException { + CanNotFoundOIDCAuthority([super.message]); -class CanNotFindToken implements Exception {} + @override + String get exceptionName => 'CanNotFoundOIDCAuthority'; +} -class CanRetryOIDCException implements Exception {} +class CanNotFoundOIDCLinks extends AppBaseException { + CanNotFoundOIDCLinks([super.message]); -class NotFoundUserInfoEndpointException implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'CanNotFoundOIDCLinks'; +} + +class CanNotFindToken extends AppBaseException { + CanNotFindToken([super.message]); + + @override + String get exceptionName => 'CanNotFindToken'; +} + +class CanRetryOIDCException extends AppBaseException { + CanRetryOIDCException([super.message]); + + @override + String get exceptionName => 'CanRetryOIDCException'; +} + +class NotFoundUserInfoEndpointException extends AppBaseException { + NotFoundUserInfoEndpointException([super.message]); + + @override + String get exceptionName => 'NotFoundUserInfoEndpointException'; +} diff --git a/lib/features/login/domain/exceptions/authentication_exception.dart b/lib/features/login/domain/exceptions/authentication_exception.dart index 4fa228454..44fe9dc44 100644 --- a/lib/features/login/domain/exceptions/authentication_exception.dart +++ b/lib/features/login/domain/exceptions/authentication_exception.dart @@ -1,4 +1,4 @@ - +import 'package:core/domain/exceptions/app_base_exception.dart'; import 'package:tmail_ui_user/main/exceptions/remote_exception.dart'; abstract class AuthenticationException extends RemoteException { @@ -11,37 +11,94 @@ abstract class AuthenticationException extends RemoteException { class BadCredentials extends AuthenticationException { BadCredentials() : super(AuthenticationException.wrongCredential); + + @override + String get exceptionName => 'BadCredentials'; } class BadGateway extends AuthenticationException { BadGateway() : super(AuthenticationException.badGateway); + + @override + String get exceptionName => 'BadGateway'; } -class NotFoundAuthenticatedAccountException implements Exception {} - -class NotFoundStoredTokenException implements Exception {} - class InvalidBaseUrl extends AuthenticationException { InvalidBaseUrl() : super(AuthenticationException.invalidBaseUrl); + + @override + String get exceptionName => 'InvalidBaseUrl'; } -class AccessTokenInvalidException implements Exception {} +class NotFoundAuthenticatedAccountException extends AppBaseException { + NotFoundAuthenticatedAccountException([super.message]); -class DownloadAttachmentHasTokenExpiredException implements Exception { + @override + String get exceptionName => 'NotFoundAuthenticatedAccountException'; +} +class NotFoundStoredTokenException extends AppBaseException { + NotFoundStoredTokenException([super.message]); + + @override + String get exceptionName => 'NotFoundStoredTokenException'; +} + +class AccessTokenInvalidException extends AppBaseException { + AccessTokenInvalidException([super.message]); + + @override + String get exceptionName => 'AccessTokenInvalidException'; +} + +class DownloadAttachmentHasTokenExpiredException extends AppBaseException { final String refreshToken; - DownloadAttachmentHasTokenExpiredException(this.refreshToken); + DownloadAttachmentHasTokenExpiredException(this.refreshToken) + : super('Token expired for refresh token: $refreshToken'); + + @override + String get exceptionName => 'DownloadAttachmentHasTokenExpiredException'; } -class CanNotFoundBaseUrl implements Exception {} +class CanNotFoundBaseUrl extends AppBaseException { + CanNotFoundBaseUrl([super.message]); -class CanNotFoundUserName implements Exception {} + @override + String get exceptionName => 'CanNotFoundBaseUrl'; +} -class CanNotFoundPassword implements Exception {} +class CanNotFoundUserName extends AppBaseException { + CanNotFoundUserName([super.message]); -class NotFoundAuthenticationInfoCache implements Exception {} + @override + String get exceptionName => 'CanNotFoundUserName'; +} -class CanNotFoundSaasServerUrl implements Exception {} +class CanNotFoundPassword extends AppBaseException { + CanNotFoundPassword([super.message]); -class SaasServerUriIsNull implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'CanNotFoundPassword'; +} + +class NotFoundAuthenticationInfoCache extends AppBaseException { + NotFoundAuthenticationInfoCache([super.message]); + + @override + String get exceptionName => 'NotFoundAuthenticationInfoCache'; +} + +class CanNotFoundSaasServerUrl extends AppBaseException { + CanNotFoundSaasServerUrl([super.message]); + + @override + String get exceptionName => 'CanNotFoundSaasServerUrl'; +} + +class SaasServerUriIsNull extends AppBaseException { + SaasServerUriIsNull([super.message]); + + @override + String get exceptionName => 'SaasServerUriIsNull'; +} diff --git a/lib/features/login/domain/exceptions/login_exception.dart b/lib/features/login/domain/exceptions/login_exception.dart index e9faa73bc..f9ca1101b 100644 --- a/lib/features/login/domain/exceptions/login_exception.dart +++ b/lib/features/login/domain/exceptions/login_exception.dart @@ -1,16 +1,35 @@ - import 'package:flutter/services.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundDataResourceRecordException implements Exception {} +class NotFoundDataResourceRecordException extends AppBaseException { + NotFoundDataResourceRecordException([super.message]); -class NotFoundUrlException implements Exception {} + @override + String get exceptionName => 'NotFoundDataResourceRecordException'; +} -class InvalidOIDCResponseException implements Exception {} +class NotFoundUrlException extends AppBaseException { + NotFoundUrlException([super.message]); -class NoSuitableBrowserForOIDCException implements Exception { + @override + String get exceptionName => 'NotFoundUrlException'; +} +class InvalidOIDCResponseException extends AppBaseException { + InvalidOIDCResponseException([super.message]); + + @override + String get exceptionName => 'InvalidOIDCResponseException'; +} + +class NoSuitableBrowserForOIDCException extends AppBaseException { static const noBrowserAvailableCode = 'no_browser_available'; + NoSuitableBrowserForOIDCException([super.message]); + + @override + String get exceptionName => 'NoSuitableBrowserForOIDCException'; + static bool verifyException(dynamic exception) { if (exception is PlatformException) { if (exception.code == noBrowserAvailableCode) { @@ -21,5 +40,9 @@ class NoSuitableBrowserForOIDCException implements Exception { } } -class NotFoundCompanyServerLoginInfoException implements Exception {} +class NotFoundCompanyServerLoginInfoException extends AppBaseException { + NotFoundCompanyServerLoginInfoException([super.message]); + @override + String get exceptionName => 'NotFoundCompanyServerLoginInfoException'; +} diff --git a/lib/features/login/domain/exceptions/logout_exception.dart b/lib/features/login/domain/exceptions/logout_exception.dart index 92b7d4b92..42303e9af 100644 --- a/lib/features/login/domain/exceptions/logout_exception.dart +++ b/lib/features/login/domain/exceptions/logout_exception.dart @@ -1 +1,8 @@ -class UserCancelledLogoutOIDCFlowException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class UserCancelledLogoutOIDCFlowException extends AppBaseException { + UserCancelledLogoutOIDCFlowException([super.message]); + + @override + String get exceptionName => 'UserCancelledLogoutOIDCFlowException'; +} diff --git a/lib/features/login/domain/exceptions/oauth_authorization_error.dart b/lib/features/login/domain/exceptions/oauth_authorization_error.dart index 65a8d5efa..167a6cba3 100644 --- a/lib/features/login/domain/exceptions/oauth_authorization_error.dart +++ b/lib/features/login/domain/exceptions/oauth_authorization_error.dart @@ -1,15 +1,27 @@ -class OAuthAuthorizationError { +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class OAuthAuthorizationError extends AppBaseException { static const String serverError = 'server_error'; // HTTP 500 error code static const String temporarilyUnavailable = 'temporarily_unavailable'; // HTTP 503 error code final String error; - final String? errorDescription; const OAuthAuthorizationError({ required this.error, - this.errorDescription, - }); + String? errorDescription, + }) : super(errorDescription); + + @override + String get exceptionName => 'OAuthAuthorizationError'; + + @override + String toString() { + if (message != null && message!.isNotEmpty) { + return '$exceptionName(code: $error): $message'; + } + return '$exceptionName(code: $error)'; + } static OAuthAuthorizationError fromErrorCode( String error, { @@ -30,11 +42,23 @@ class OAuthAuthorizationError { } class ServerError extends OAuthAuthorizationError { - const ServerError({super.errorDescription}) - : super(error: OAuthAuthorizationError.serverError); + const ServerError({String? errorDescription}) + : super( + error: OAuthAuthorizationError.serverError, + errorDescription: errorDescription, + ); + + @override + String get exceptionName => 'ServerError'; } class TemporarilyUnavailable extends OAuthAuthorizationError { - const TemporarilyUnavailable({super.errorDescription}) - : super(error: OAuthAuthorizationError.temporarilyUnavailable); + const TemporarilyUnavailable({String? errorDescription}) + : super( + error: OAuthAuthorizationError.temporarilyUnavailable, + errorDescription: errorDescription, + ); + + @override + String get exceptionName => 'TemporarilyUnavailable'; } diff --git a/lib/features/mailbox/data/network/mailbox_isolate_worker.dart b/lib/features/mailbox/data/network/mailbox_isolate_worker.dart index c745247cd..7c664c35c 100644 --- a/lib/features/mailbox/data/network/mailbox_isolate_worker.dart +++ b/lib/features/mailbox/data/network/mailbox_isolate_worker.dart @@ -60,7 +60,7 @@ class MailboxIsolateWorker { } else { final rootIsolateToken = RootIsolateToken.instance; if (rootIsolateToken == null) { - throw CanNotGetRootIsolateToken(); + throw const CanNotGetRootIsolateToken(); } final result = await _isolateExecutor.execute( @@ -227,7 +227,7 @@ class MailboxIsolateWorker { }) async { final rootIsolateToken = RootIsolateToken.instance; if (rootIsolateToken == null) { - throw CanNotGetRootIsolateToken(); + throw const CanNotGetRootIsolateToken(); } final countEmailsCompleted = await _isolateExecutor.execute( diff --git a/lib/features/mailbox/domain/exceptions/empty_folder_name_exception.dart b/lib/features/mailbox/domain/exceptions/empty_folder_name_exception.dart index 5a3ff99dd..34b7bca45 100644 --- a/lib/features/mailbox/domain/exceptions/empty_folder_name_exception.dart +++ b/lib/features/mailbox/domain/exceptions/empty_folder_name_exception.dart @@ -1,9 +1,11 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class EmptyFolderNameException implements Exception { +class EmptyFolderNameException extends AppBaseException { final String folderName; - EmptyFolderNameException(this.folderName); + EmptyFolderNameException(this.folderName) + : super('Folder name should not be empty: $folderName'); @override - String toString() => 'EmptyFolderNameException: Folder name should not be empty: $folderName'; + String get exceptionName => 'EmptyFolderNameException'; } diff --git a/lib/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart b/lib/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart index bd15b87b2..ccb01119c 100644 --- a/lib/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart +++ b/lib/features/mailbox/domain/exceptions/invalid_mail_format_exception.dart @@ -1,9 +1,10 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class InvalidMailFormatException implements Exception { +class InvalidMailFormatException extends AppBaseException { final String mail; - InvalidMailFormatException(this.mail); + InvalidMailFormatException(this.mail) : super('Email: $mail'); @override - String toString() => 'InvalidMailFormatException: $mail'; + String get exceptionName => 'InvalidMailFormatException'; } diff --git a/lib/features/mailbox/domain/exceptions/mailbox_exception.dart b/lib/features/mailbox/domain/exceptions/mailbox_exception.dart index de530621d..0d6b89f8d 100644 --- a/lib/features/mailbox/domain/exceptions/mailbox_exception.dart +++ b/lib/features/mailbox/domain/exceptions/mailbox_exception.dart @@ -1,8 +1,29 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundInboxMailboxException implements Exception {} +class NotFoundInboxMailboxException extends AppBaseException { + NotFoundInboxMailboxException([super.message]); -class NotFoundMailboxException implements Exception {} + @override + String get exceptionName => 'NotFoundInboxMailboxException'; +} -class NotFoundClearMailboxResponseException implements Exception {} +class NotFoundMailboxException extends AppBaseException { + NotFoundMailboxException([super.message]); -class CannotMoveAllEmailException implements Exception {} + @override + String get exceptionName => 'NotFoundMailboxException'; +} + +class NotFoundClearMailboxResponseException extends AppBaseException { + NotFoundClearMailboxResponseException([super.message]); + + @override + String get exceptionName => 'NotFoundClearMailboxResponseException'; +} + +class CannotMoveAllEmailException extends AppBaseException { + CannotMoveAllEmailException([super.message]); + + @override + String get exceptionName => 'CannotMoveAllEmailException'; +} diff --git a/lib/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart b/lib/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart index 2e9bc3e7b..95410785f 100644 --- a/lib/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart +++ b/lib/features/mailbox/domain/exceptions/null_session_or_accountid_exception.dart @@ -1,8 +1,9 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NullSessionOrAccountIdException implements Exception { - - NullSessionOrAccountIdException(); +class NullSessionOrAccountIdException extends AppBaseException { + NullSessionOrAccountIdException( + [super.message = 'session and accountId should not be null']); @override - String toString() => 'NullSessionOrAccountIdException: session and accountId should not be null'; + String get exceptionName => 'NullSessionOrAccountIdException'; } diff --git a/lib/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart b/lib/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart index 9585b5c45..5de108212 100644 --- a/lib/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart +++ b/lib/features/mailbox/domain/exceptions/set_mailbox_method_exception.dart @@ -1,3 +1,15 @@ -class NotFoundMailboxCreatedException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundMailboxUpdatedRoleException implements Exception {} \ No newline at end of file +class NotFoundMailboxCreatedException extends AppBaseException { + NotFoundMailboxCreatedException([super.message]); + + @override + String get exceptionName => 'NotFoundMailboxCreatedException'; +} + +class NotFoundMailboxUpdatedRoleException extends AppBaseException { + NotFoundMailboxUpdatedRoleException([super.message]); + + @override + String get exceptionName => 'NotFoundMailboxUpdatedRoleException'; +} diff --git a/lib/features/mailbox/domain/exceptions/set_mailbox_name_exception.dart b/lib/features/mailbox/domain/exceptions/set_mailbox_name_exception.dart index 3f379df31..3f0c6b6e6 100644 --- a/lib/features/mailbox/domain/exceptions/set_mailbox_name_exception.dart +++ b/lib/features/mailbox/domain/exceptions/set_mailbox_name_exception.dart @@ -1,11 +1,20 @@ import 'package:jmap_dart_client/jmap/mail/mailbox/mailbox.dart'; import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -class SetMailboxNameException implements Exception { - static const emptyMailboxNameDescription = 'has an empty part within its mailbox name'; - static const mailboxNameContainsInvalidCharactersDescription = 'contains one of the forbidden characters'; +class SetMailboxNameException extends AppBaseException { + static const emptyMailboxNameDescription = + 'has an empty part within its mailbox name'; + static const mailboxNameContainsInvalidCharactersDescription = + 'contains one of the forbidden characters'; - static SetMailboxNameException detectMailboxNameException(Object exception, MailboxId mailboxId) { + SetMailboxNameException([super.message]); + + @override + String get exceptionName => 'SetMailboxNameException'; + + static SetMailboxNameException detectMailboxNameException( + Object exception, MailboxId mailboxId) { if (exception is SetMethodException) { final setError = exception.mapErrors[mailboxId.id]; if (setError == null) { @@ -19,15 +28,30 @@ class SetMailboxNameException implements Exception { if (errorDescription.contains(emptyMailboxNameDescription)) { return EmptyMailboxNameException(); - } else if (errorDescription.contains(mailboxNameContainsInvalidCharactersDescription)) { + } else if (errorDescription + .contains(mailboxNameContainsInvalidCharactersDescription)) { return ContainsInvalidCharactersMailboxNameException(); } - return SetMailboxNameException(); + return SetMailboxNameException(errorDescription); } return SetMailboxNameException(); } } -class EmptyMailboxNameException implements SetMailboxNameException {} +class EmptyMailboxNameException extends SetMailboxNameException { + EmptyMailboxNameException() + : super(SetMailboxNameException.emptyMailboxNameDescription); -class ContainsInvalidCharactersMailboxNameException implements SetMailboxNameException {} + @override + String get exceptionName => 'EmptyMailboxNameException'; +} + +class ContainsInvalidCharactersMailboxNameException + extends SetMailboxNameException { + ContainsInvalidCharactersMailboxNameException() + : super(SetMailboxNameException + .mailboxNameContainsInvalidCharactersDescription); + + @override + String get exceptionName => 'ContainsInvalidCharactersMailboxNameException'; +} diff --git a/lib/features/mailbox/domain/exceptions/set_mailbox_rights_exception.dart b/lib/features/mailbox/domain/exceptions/set_mailbox_rights_exception.dart index 211c4b3ce..00febf377 100644 --- a/lib/features/mailbox/domain/exceptions/set_mailbox_rights_exception.dart +++ b/lib/features/mailbox/domain/exceptions/set_mailbox_rights_exception.dart @@ -1,8 +1,9 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class SetMailboxRightsException implements Exception { - - SetMailboxRightsException(); +class SetMailboxRightsException extends AppBaseException { + SetMailboxRightsException( + [super.message = 'Failed to update mailbox rights.']); @override - String toString() => 'Failed to update mailbox rights.'; -} \ No newline at end of file + String get exceptionName => 'SetMailboxRightsException'; +} diff --git a/lib/features/mailbox_creator/domain/exceptions/verify_name_exception.dart b/lib/features/mailbox_creator/domain/exceptions/verify_name_exception.dart index 7fbcc7f4e..f06468578 100644 --- a/lib/features/mailbox_creator/domain/exceptions/verify_name_exception.dart +++ b/lib/features/mailbox_creator/domain/exceptions/verify_name_exception.dart @@ -1,37 +1,55 @@ - import 'package:equatable/equatable.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; -abstract class VerifyNameException extends Equatable implements Exception { +abstract class VerifyNameException extends AppBaseException + with EquatableMixin { static const emptyName = 'The name cannot be empty!'; static const duplicatedName = 'The name already exists!'; - static const nameContainSpecialCharacter = 'The name cannot contain special characters'; + static const nameContainSpecialCharacter = + 'The name cannot contain special characters'; static const emailAddressInvalid = 'The email address invalid'; static const spaceOnlyWithinName = 'The name cannot contain only spaces'; - final String? message; - - const VerifyNameException(this.message); + const VerifyNameException(super.message); @override - List get props => [message]; + List get props => [message, exceptionName]; } class EmptyNameException extends VerifyNameException { const EmptyNameException() : super(VerifyNameException.emptyName); + + @override + String get exceptionName => 'EmptyNameException'; } class DuplicatedNameException extends VerifyNameException { const DuplicatedNameException() : super(VerifyNameException.duplicatedName); + + @override + String get exceptionName => 'DuplicatedNameException'; } class SpecialCharacterException extends VerifyNameException { - const SpecialCharacterException() : super(VerifyNameException.nameContainSpecialCharacter); + const SpecialCharacterException() + : super(VerifyNameException.nameContainSpecialCharacter); + + @override + String get exceptionName => 'SpecialCharacterException'; } class EmailAddressInvalidException extends VerifyNameException { - const EmailAddressInvalidException() : super(VerifyNameException.emailAddressInvalid); + const EmailAddressInvalidException() + : super(VerifyNameException.emailAddressInvalid); + + @override + String get exceptionName => 'EmailAddressInvalidException'; } class NameWithSpaceOnlyException extends VerifyNameException { - const NameWithSpaceOnlyException() : super(VerifyNameException.spaceOnlyWithinName); -} \ No newline at end of file + const NameWithSpaceOnlyException() + : super(VerifyNameException.spaceOnlyWithinName); + + @override + String get exceptionName => 'NameWithSpaceOnlyException'; +} diff --git a/lib/features/mailbox_dashboard/data/datasource_impl/session_storage_composer_datasoure_impl.dart b/lib/features/mailbox_dashboard/data/datasource_impl/session_storage_composer_datasoure_impl.dart index 824140b42..351f24c44 100644 --- a/lib/features/mailbox_dashboard/data/datasource_impl/session_storage_composer_datasoure_impl.dart +++ b/lib/features/mailbox_dashboard/data/datasource_impl/session_storage_composer_datasoure_impl.dart @@ -39,7 +39,7 @@ class SessionStorageComposerDatasourceImpl .map((entry) => ComposerCache.fromJson(jsonDecode(entry.value))) .toList(); } else { - throw NotFoundInWebSessionException(); + throw const NotFoundInWebSessionException(); } }).catchError(_exceptionThrower.throwException); } diff --git a/lib/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart b/lib/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart index fe58d14cb..00fdb2fc7 100644 --- a/lib/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart +++ b/lib/features/mailbox_dashboard/domain/exceptions/linagora_ecosystem_exceptions.dart @@ -1,4 +1,15 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundLinagoraEcosystem implements Exception {} +class NotFoundLinagoraEcosystem extends AppBaseException { + NotFoundLinagoraEcosystem([super.message]); -class NotFoundPaywallUrl implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'NotFoundLinagoraEcosystem'; +} + +class NotFoundPaywallUrl extends AppBaseException { + NotFoundPaywallUrl([super.message]); + + @override + String get exceptionName => 'NotFoundPaywallUrl'; +} diff --git a/lib/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart b/lib/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart index 21917bc85..a361d9bc4 100644 --- a/lib/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart +++ b/lib/features/mailbox_dashboard/domain/exceptions/spam_report_exception.dart @@ -1,6 +1,22 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundLastTimeDismissedSpamReportException implements Exception {} +class NotFoundLastTimeDismissedSpamReportException extends AppBaseException { + NotFoundLastTimeDismissedSpamReportException([super.message]); -class NotFoundSpamMailboxCachedException implements Exception {} + @override + String get exceptionName => 'NotFoundLastTimeDismissedSpamReportException'; +} -class NotFoundSpamMailboxException implements Exception {} \ No newline at end of file +class NotFoundSpamMailboxCachedException extends AppBaseException { + NotFoundSpamMailboxCachedException([super.message]); + + @override + String get exceptionName => 'NotFoundSpamMailboxCachedException'; +} + +class NotFoundSpamMailboxException extends AppBaseException { + NotFoundSpamMailboxException([super.message]); + + @override + String get exceptionName => 'NotFoundSpamMailboxException'; +} diff --git a/lib/features/manage_account/domain/exceptions/forward_exception.dart b/lib/features/manage_account/domain/exceptions/forward_exception.dart index 22e3d2931..ac8b95729 100644 --- a/lib/features/manage_account/domain/exceptions/forward_exception.dart +++ b/lib/features/manage_account/domain/exceptions/forward_exception.dart @@ -1,7 +1,29 @@ -class NotFoundForwardException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class UpdateForwardException implements Exception {} +class NotFoundForwardException extends AppBaseException { + NotFoundForwardException([super.message]); -class RecipientListIsEmptyException implements Exception {} + @override + String get exceptionName => 'NotFoundForwardException'; +} -class RecipientListWithInvalidEmailsException implements Exception {} \ No newline at end of file +class UpdateForwardException extends AppBaseException { + UpdateForwardException([super.message]); + + @override + String get exceptionName => 'UpdateForwardException'; +} + +class RecipientListIsEmptyException extends AppBaseException { + RecipientListIsEmptyException([super.message]); + + @override + String get exceptionName => 'RecipientListIsEmptyException'; +} + +class RecipientListWithInvalidEmailsException extends AppBaseException { + RecipientListWithInvalidEmailsException([super.message]); + + @override + String get exceptionName => 'RecipientListWithInvalidEmailsException'; +} diff --git a/lib/features/manage_account/domain/exceptions/rule_filter_exception.dart b/lib/features/manage_account/domain/exceptions/rule_filter_exception.dart index 8d36ccca4..d3bcb611a 100644 --- a/lib/features/manage_account/domain/exceptions/rule_filter_exception.dart +++ b/lib/features/manage_account/domain/exceptions/rule_filter_exception.dart @@ -1,2 +1,8 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class RuleFilterNotBindingException implements Exception {} \ No newline at end of file +class RuleFilterNotBindingException extends AppBaseException { + RuleFilterNotBindingException([super.message]); + + @override + String get exceptionName => 'RuleFilterNotBindingException'; +} diff --git a/lib/features/public_asset/domain/exceptions/public_asset_exceptions.dart b/lib/features/public_asset/domain/exceptions/public_asset_exceptions.dart index ee3b40398..83025758b 100644 --- a/lib/features/public_asset/domain/exceptions/public_asset_exceptions.dart +++ b/lib/features/public_asset/domain/exceptions/public_asset_exceptions.dart @@ -1,17 +1,29 @@ -class CannotCreatePublicAssetException implements Exception { - const CannotCreatePublicAssetException(); +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class CannotCreatePublicAssetException extends AppBaseException { + const CannotCreatePublicAssetException([super.message]); + + @override + String get exceptionName => 'CannotCreatePublicAssetException'; } -class PublicAssetQuotaExceededException implements Exception { - const PublicAssetQuotaExceededException({required this.message}); +class PublicAssetQuotaExceededException extends AppBaseException { + const PublicAssetQuotaExceededException({String? message}) : super(message); - final String? message; + @override + String get exceptionName => 'PublicAssetQuotaExceededException'; } -class CannotDestroyPublicAssetException implements Exception { - const CannotDestroyPublicAssetException(); +class CannotDestroyPublicAssetException extends AppBaseException { + const CannotDestroyPublicAssetException([super.message]); + + @override + String get exceptionName => 'CannotDestroyPublicAssetException'; } -class CannotUpdatePublicAssetException implements Exception { - const CannotUpdatePublicAssetException(); -} \ No newline at end of file +class CannotUpdatePublicAssetException extends AppBaseException { + const CannotUpdatePublicAssetException([super.message]); + + @override + String get exceptionName => 'CannotUpdatePublicAssetException'; +} diff --git a/lib/features/push_notification/domain/exceptions/fcm_exception.dart b/lib/features/push_notification/domain/exceptions/fcm_exception.dart index 9a6377f22..e450ea3f4 100644 --- a/lib/features/push_notification/domain/exceptions/fcm_exception.dart +++ b/lib/features/push_notification/domain/exceptions/fcm_exception.dart @@ -1,23 +1,85 @@ -class NotSupportFCMException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotLoadedFCMTokenException implements Exception {} +class NotSupportFCMException extends AppBaseException { + NotSupportFCMException([super.message]); -class NotFoundStateToRefreshException implements Exception {} + @override + String get exceptionName => 'NotSupportFCMException'; +} -class NotFoundEmailDeliveryStateException implements Exception {} +class NotLoadedFCMTokenException extends AppBaseException { + NotLoadedFCMTokenException([super.message]); -class NotFoundFirebaseRegistrationForDeviceException implements Exception {} + @override + String get exceptionName => 'NotLoadedFCMTokenException'; +} -class NotFoundFirebaseRegistrationCacheException implements Exception {} +class NotFoundStateToRefreshException extends AppBaseException { + NotFoundStateToRefreshException([super.message]); -class NotFoundEmailStateException implements Exception {} + @override + String get exceptionName => 'NotFoundStateToRefreshException'; +} -class NotFoundNewReceiveEmailException implements Exception {} +class NotFoundEmailDeliveryStateException extends AppBaseException { + NotFoundEmailDeliveryStateException([super.message]); -class EmailStateNoChangeException implements Exception {} + @override + String get exceptionName => 'NotFoundEmailDeliveryStateException'; +} -class NotFoundFirebaseRegistrationCreatedException implements Exception {} +class NotFoundFirebaseRegistrationForDeviceException extends AppBaseException { + NotFoundFirebaseRegistrationForDeviceException([super.message]); -class NotFoundFirebaseRegistrationUpdatedException implements Exception {} + @override + String get exceptionName => 'NotFoundFirebaseRegistrationForDeviceException'; +} -class NotFoundFirebaseRegistrationDestroyedException implements Exception {} \ No newline at end of file +class NotFoundFirebaseRegistrationCacheException extends AppBaseException { + NotFoundFirebaseRegistrationCacheException([super.message]); + + @override + String get exceptionName => 'NotFoundFirebaseRegistrationCacheException'; +} + +class NotFoundEmailStateException extends AppBaseException { + NotFoundEmailStateException([super.message]); + + @override + String get exceptionName => 'NotFoundEmailStateException'; +} + +class NotFoundNewReceiveEmailException extends AppBaseException { + NotFoundNewReceiveEmailException([super.message]); + + @override + String get exceptionName => 'NotFoundNewReceiveEmailException'; +} + +class EmailStateNoChangeException extends AppBaseException { + EmailStateNoChangeException([super.message]); + + @override + String get exceptionName => 'EmailStateNoChangeException'; +} + +class NotFoundFirebaseRegistrationCreatedException extends AppBaseException { + NotFoundFirebaseRegistrationCreatedException([super.message]); + + @override + String get exceptionName => 'NotFoundFirebaseRegistrationCreatedException'; +} + +class NotFoundFirebaseRegistrationUpdatedException extends AppBaseException { + NotFoundFirebaseRegistrationUpdatedException([super.message]); + + @override + String get exceptionName => 'NotFoundFirebaseRegistrationUpdatedException'; +} + +class NotFoundFirebaseRegistrationDestroyedException extends AppBaseException { + NotFoundFirebaseRegistrationDestroyedException([super.message]); + + @override + String get exceptionName => 'NotFoundFirebaseRegistrationDestroyedException'; +} diff --git a/lib/features/push_notification/domain/exceptions/web_socket_exceptions.dart b/lib/features/push_notification/domain/exceptions/web_socket_exceptions.dart index 216b4c126..d9ccdc1c0 100644 --- a/lib/features/push_notification/domain/exceptions/web_socket_exceptions.dart +++ b/lib/features/push_notification/domain/exceptions/web_socket_exceptions.dart @@ -1,7 +1,29 @@ -class WebSocketPushNotSupportedException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class WebSocketUriUnavailableException implements Exception {} +class WebSocketPushNotSupportedException extends AppBaseException { + WebSocketPushNotSupportedException([super.message]); -class WebSocketTicketUnavailableException implements Exception {} + @override + String get exceptionName => 'WebSocketPushNotSupportedException'; +} -class WebSocketClosedException implements Exception {} \ No newline at end of file +class WebSocketUriUnavailableException extends AppBaseException { + WebSocketUriUnavailableException([super.message]); + + @override + String get exceptionName => 'WebSocketUriUnavailableException'; +} + +class WebSocketTicketUnavailableException extends AppBaseException { + WebSocketTicketUnavailableException([super.message]); + + @override + String get exceptionName => 'WebSocketTicketUnavailableException'; +} + +class WebSocketClosedException extends AppBaseException { + WebSocketClosedException([super.message]); + + @override + String get exceptionName => 'WebSocketClosedException'; +} diff --git a/lib/features/quotas/domain/exceptions/quotas_exception.dart b/lib/features/quotas/domain/exceptions/quotas_exception.dart index a6e3bda8d..d021aab73 100644 --- a/lib/features/quotas/domain/exceptions/quotas_exception.dart +++ b/lib/features/quotas/domain/exceptions/quotas_exception.dart @@ -1,3 +1,15 @@ -class NotFoundQuotasException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class QuotasNotSupportedException implements Exception {} +class NotFoundQuotasException extends AppBaseException { + NotFoundQuotasException([super.message]); + + @override + String get exceptionName => 'NotFoundQuotasException'; +} + +class QuotasNotSupportedException extends AppBaseException { + QuotasNotSupportedException([super.message]); + + @override + String get exceptionName => 'QuotasNotSupportedException'; +} diff --git a/lib/features/sending_queue/data/exceptions/sending_queue_exceptions.dart b/lib/features/sending_queue/data/exceptions/sending_queue_exceptions.dart index ab1649479..d1eaec150 100644 --- a/lib/features/sending_queue/data/exceptions/sending_queue_exceptions.dart +++ b/lib/features/sending_queue/data/exceptions/sending_queue_exceptions.dart @@ -1,4 +1,15 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundSendingEmailHiveObject implements Exception {} +class NotFoundSendingEmailHiveObject extends AppBaseException { + NotFoundSendingEmailHiveObject([super.message]); -class ExistSendingEmailHiveObject implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'NotFoundSendingEmailHiveObject'; +} + +class ExistSendingEmailHiveObject extends AppBaseException { + ExistSendingEmailHiveObject([super.message]); + + @override + String get exceptionName => 'ExistSendingEmailHiveObject'; +} diff --git a/lib/features/server_settings/domain/exceptions/server_settings_exception.dart b/lib/features/server_settings/domain/exceptions/server_settings_exception.dart index 63e1eefe5..b9c9c7aa9 100644 --- a/lib/features/server_settings/domain/exceptions/server_settings_exception.dart +++ b/lib/features/server_settings/domain/exceptions/server_settings_exception.dart @@ -1,5 +1,22 @@ -class NotFoundServerSettingsException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundSettingOptionException implements Exception {} +class NotFoundServerSettingsException extends AppBaseException { + NotFoundServerSettingsException([super.message]); -class CanNotUpdateServerSettingsException implements Exception {} \ No newline at end of file + @override + String get exceptionName => 'NotFoundServerSettingsException'; +} + +class NotFoundSettingOptionException extends AppBaseException { + NotFoundSettingOptionException([super.message]); + + @override + String get exceptionName => 'NotFoundSettingOptionException'; +} + +class CanNotUpdateServerSettingsException extends AppBaseException { + CanNotUpdateServerSettingsException([super.message]); + + @override + String get exceptionName => 'CanNotUpdateServerSettingsException'; +} diff --git a/lib/features/thread/data/network/thread_isolate_worker.dart b/lib/features/thread/data/network/thread_isolate_worker.dart index b0713dde0..2505ddfc8 100644 --- a/lib/features/thread/data/network/thread_isolate_worker.dart +++ b/lib/features/thread/data/network/thread_isolate_worker.dart @@ -46,7 +46,7 @@ class ThreadIsolateWorker { } else { final rootIsolateToken = RootIsolateToken.instance; if (rootIsolateToken == null) { - throw CanNotGetRootIsolateToken(); + throw const CanNotGetRootIsolateToken(); } final result = await _isolateExecutor.execute( diff --git a/lib/features/thread/domain/exceptions/thread_exceptions.dart b/lib/features/thread/domain/exceptions/thread_exceptions.dart index 8941b507a..5edb173e2 100644 --- a/lib/features/thread/domain/exceptions/thread_exceptions.dart +++ b/lib/features/thread/domain/exceptions/thread_exceptions.dart @@ -1,3 +1,15 @@ -class NotFoundEmailsDeletedException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class InteractorIsNullException implements Exception {} \ No newline at end of file +class NotFoundEmailsDeletedException extends AppBaseException { + NotFoundEmailsDeletedException([super.message]); + + @override + String get exceptionName => 'NotFoundEmailsDeletedException'; +} + +class InteractorIsNullException extends AppBaseException { + InteractorIsNullException([super.message]); + + @override + String get exceptionName => 'InteractorIsNullException'; +} diff --git a/lib/features/thread_detail/domain/exceptions/empty_thread_detail_exception.dart b/lib/features/thread_detail/domain/exceptions/empty_thread_detail_exception.dart index 699fa20b2..a037dd95d 100644 --- a/lib/features/thread_detail/domain/exceptions/empty_thread_detail_exception.dart +++ b/lib/features/thread_detail/domain/exceptions/empty_thread_detail_exception.dart @@ -1 +1,8 @@ -class EmptyThreadDetailException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class EmptyThreadDetailException extends AppBaseException { + EmptyThreadDetailException([super.message]); + + @override + String get exceptionName => 'EmptyThreadDetailException'; +} diff --git a/lib/features/thread_detail/domain/exceptions/thread_detail_overload_exception.dart b/lib/features/thread_detail/domain/exceptions/thread_detail_overload_exception.dart index f3d914392..706b7b457 100644 --- a/lib/features/thread_detail/domain/exceptions/thread_detail_overload_exception.dart +++ b/lib/features/thread_detail/domain/exceptions/thread_detail_overload_exception.dart @@ -1 +1,8 @@ -class ThreadDetailOverloadException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class ThreadDetailOverloadException extends AppBaseException { + ThreadDetailOverloadException([super.message]); + + @override + String get exceptionName => 'ThreadDetailOverloadException'; +} diff --git a/lib/features/upload/data/network/file_uploader.dart b/lib/features/upload/data/network/file_uploader.dart index 5492708f3..dd8599854 100644 --- a/lib/features/upload/data/network/file_uploader.dart +++ b/lib/features/upload/data/network/file_uploader.dart @@ -60,7 +60,7 @@ class FileUploader { } else { final rootIsolateToken = RootIsolateToken.instance; if (rootIsolateToken == null) { - throw CanNotGetRootIsolateToken(); + throw const CanNotGetRootIsolateToken(); } return await _isolateExecutor.execute( diff --git a/lib/features/upload/domain/exceptions/pick_file_exception.dart b/lib/features/upload/domain/exceptions/pick_file_exception.dart index 0620cf3a1..f83dbe4d4 100644 --- a/lib/features/upload/domain/exceptions/pick_file_exception.dart +++ b/lib/features/upload/domain/exceptions/pick_file_exception.dart @@ -1 +1,8 @@ -class PickFileCanceledException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class PickFileCanceledException extends AppBaseException { + PickFileCanceledException([super.message]); + + @override + String get exceptionName => 'PickFileCanceledException'; +} diff --git a/lib/features/upload/domain/exceptions/upload_exception.dart b/lib/features/upload/domain/exceptions/upload_exception.dart index a56e36d56..0b5627a08 100644 --- a/lib/features/upload/domain/exceptions/upload_exception.dart +++ b/lib/features/upload/domain/exceptions/upload_exception.dart @@ -1 +1,8 @@ -class DataResponseIsNullException implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class DataResponseIsNullException extends AppBaseException { + DataResponseIsNullException([super.message]); + + @override + String get exceptionName => 'DataResponseIsNullException'; +} diff --git a/lib/main/error/request_error.dart b/lib/main/error/request_error.dart index c89511035..1a09afdfa 100644 --- a/lib/main/error/request_error.dart +++ b/lib/main/error/request_error.dart @@ -1,18 +1,26 @@ import 'package:equatable/equatable.dart'; import 'package:jmap_dart_client/jmap/core/capability/capability_identifier.dart'; +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class InvalidCapability extends AppBaseException with EquatableMixin { + const InvalidCapability([super.message]); + + @override + String get exceptionName => 'InvalidCapability'; + + @override + List get props => [message]; +} class SessionMissingCapability extends InvalidCapability { final Set capabilityIdentifiers; - const SessionMissingCapability(this.capabilityIdentifiers) : super(); + const SessionMissingCapability(this.capabilityIdentifiers) + : super('Missing capabilities $capabilityIdentifiers'); @override - List get props => [capabilityIdentifiers]; + String get exceptionName => 'SessionMissingCapability'; + + @override + List get props => [capabilityIdentifiers, ...super.props]; } - -class InvalidCapability extends Equatable implements Exception { - const InvalidCapability(); - - @override - List get props => []; -} \ No newline at end of file diff --git a/lib/main/exceptions/cache_exception.dart b/lib/main/exceptions/cache_exception.dart index cf83c56a4..ae90e3677 100644 --- a/lib/main/exceptions/cache_exception.dart +++ b/lib/main/exceptions/cache_exception.dart @@ -1,16 +1,27 @@ - import 'package:equatable/equatable.dart'; abstract class CacheException with EquatableMixin implements Exception { - final String? message; const CacheException({this.message}); + + String get exceptionName; + + @override + String toString() { + if (message != null) { + return '$exceptionName: $message'; + } + return exceptionName; + } } class UnknownCacheError extends CacheException { const UnknownCacheError({String? message}) : super(message: message); @override - List get props => []; -} \ No newline at end of file + String get exceptionName => 'UnknownCacheError'; + + @override + List get props => [message]; +} diff --git a/lib/main/exceptions/isolate_exception.dart b/lib/main/exceptions/isolate_exception.dart index f6046321f..154326ae4 100644 --- a/lib/main/exceptions/isolate_exception.dart +++ b/lib/main/exceptions/isolate_exception.dart @@ -1 +1,8 @@ -class CanNotGetRootIsolateToken implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class CanNotGetRootIsolateToken extends AppBaseException { + const CanNotGetRootIsolateToken([super.message]); + + @override + String get exceptionName => 'CanNotGetRootIsolateToken'; +} diff --git a/lib/main/exceptions/logic_exception.dart b/lib/main/exceptions/logic_exception.dart index de075cede..16408630b 100644 --- a/lib/main/exceptions/logic_exception.dart +++ b/lib/main/exceptions/logic_exception.dart @@ -1 +1,8 @@ -class InteractorNotInitialized implements Exception {} \ No newline at end of file +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class InteractorNotInitialized extends AppBaseException { + const InteractorNotInitialized([super.message]); + + @override + String get exceptionName => 'InteractorNotInitialized'; +} \ No newline at end of file diff --git a/lib/main/exceptions/permission_exception.dart b/lib/main/exceptions/permission_exception.dart index 69f9b2cbd..a35e594a1 100644 --- a/lib/main/exceptions/permission_exception.dart +++ b/lib/main/exceptions/permission_exception.dart @@ -1,15 +1,28 @@ import 'package:equatable/equatable.dart'; abstract class PermissionException with EquatableMixin implements Exception { - final String? message; const PermissionException({this.message}); + + String get exceptionName; + + @override + String toString() { + if (message != null) { + return '$exceptionName: $message'; + } + return exceptionName; + } } class NotGrantedPermissionStorageException extends PermissionException { - const NotGrantedPermissionStorageException() : super(message: 'Permission Storage has not been granted access'); + const NotGrantedPermissionStorageException() + : super(message: 'Permission Storage has not been granted access'); @override - List get props => [super.message]; -} \ No newline at end of file + String get exceptionName => 'NotGrantedPermissionStorageException'; + + @override + List get props => [message]; +} diff --git a/lib/main/exceptions/remote_exception.dart b/lib/main/exceptions/remote_exception.dart index e4da7cf65..da2a466be 100644 --- a/lib/main/exceptions/remote_exception.dart +++ b/lib/main/exceptions/remote_exception.dart @@ -1,4 +1,3 @@ - import 'package:equatable/equatable.dart'; import 'package:jmap_dart_client/jmap/core/error/error_type.dart'; import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; @@ -16,52 +15,98 @@ abstract class RemoteException with EquatableMixin implements Exception { const RemoteException({this.code, this.message}); + String get exceptionName; + + @override + String toString() { + if (code != null) { + return '$exceptionName(code: $code): $message'; + } + return '$exceptionName: $message'; + } + @override List get props => [message, code]; } class BadCredentialsException extends RemoteException { - const BadCredentialsException() : super(message: RemoteException.badCredentials); + const BadCredentialsException() + : super(message: RemoteException.badCredentials); + + @override + String get exceptionName => 'BadCredentialsException'; } class UnknownError extends RemoteException { - const UnknownError({int? code, Object? message}) : super(code: code, message: message); + const UnknownError({int? code, Object? message}) + : super(code: code, message: message); + + @override + String get exceptionName => 'UnknownError'; } class ConnectionError extends RemoteException { - const ConnectionError({String? message}) : super(message: message ?? RemoteException.connectionError); + const ConnectionError({String? message}) + : super(message: message ?? RemoteException.connectionError); + + @override + String get exceptionName => 'ConnectionError'; } class ConnectionTimeout extends RemoteException { - const ConnectionTimeout({String? message}) : super(message: message ?? RemoteException.connectionTimeout); + const ConnectionTimeout({String? message}) + : super(message: message ?? RemoteException.connectionTimeout); + + @override + String get exceptionName => 'ConnectionTimeout'; } class SocketError extends RemoteException { const SocketError() : super(message: RemoteException.socketException); + + @override + String get exceptionName => 'SocketError'; } class InternalServerError extends RemoteException { - const InternalServerError() : super(message: RemoteException.internalServerError); + const InternalServerError() + : super(message: RemoteException.internalServerError); + + @override + String get exceptionName => 'InternalServerError'; } class MethodLevelErrors extends RemoteException { final ErrorType type; - const MethodLevelErrors( - this.type, - {String? message} - ) : super(message: message); + const MethodLevelErrors(this.type, {String? message}) + : super(message: message); + + @override + String get exceptionName => 'MethodLevelErrors'; + + @override + String toString() { + return '$exceptionName(type: $type): $message'; + } @override List get props => [type, ...super.props]; } class CannotCalculateChangesMethodResponseException extends MethodLevelErrors { - CannotCalculateChangesMethodResponseException({String? message}) : super(ErrorMethodResponse.cannotCalculateChanges, message: message); + CannotCalculateChangesMethodResponseException({String? message}) + : super(ErrorMethodResponse.cannotCalculateChanges, message: message); + + @override + String get exceptionName => 'CannotCalculateChangesMethodResponseException'; } class NoNetworkError extends RemoteException { const NoNetworkError() : super(message: RemoteException.noNetworkError); + + @override + String get exceptionName => 'NoNetworkError'; } class RefreshTokenFailedException extends RemoteException { @@ -74,6 +119,8 @@ class RefreshTokenFailedException extends RemoteException { }); @override - String toString() => - "RefreshTokenFailedException(status: $statusCode): $message"; -} \ No newline at end of file + String get exceptionName => 'RefreshTokenFailedException'; + + @override + String toString() => "$exceptionName(status: $statusCode): $message"; +} diff --git a/lib/main/utils/toast_manager.dart b/lib/main/utils/toast_manager.dart index 7a07ef8d5..e639ca5c5 100644 --- a/lib/main/utils/toast_manager.dart +++ b/lib/main/utils/toast_manager.dart @@ -20,21 +20,21 @@ import 'package:model/email/email_action_type.dart'; import 'package:model/email/mark_star_action.dart'; import 'package:model/mailbox/presentation_mailbox.dart'; import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart'; +import 'package:tmail_ui_user/features/download/domain/state/parse_email_by_blob_id_state.dart'; +import 'package:tmail_ui_user/features/download/domain/state/preview_email_from_eml_file_state.dart'; import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart'; import 'package:tmail_ui_user/features/email/domain/model/move_action.dart'; -import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_a_thread_state.dart'; +import 'package:tmail_ui_user/features/email/domain/state/add_a_label_to_an_email_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/calendar_event_reply_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/labels/remove_a_label_from_a_thread_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/mark_as_email_star_state.dart'; -import 'package:tmail_ui_user/features/download/domain/state/parse_email_by_blob_id_state.dart'; -import 'package:tmail_ui_user/features/download/domain/state/preview_email_from_eml_file_state.dart'; import 'package:tmail_ui_user/features/email/domain/state/remove_a_label_from_an_email_state.dart'; import 'package:tmail_ui_user/features/home/data/exceptions/session_exceptions.dart'; import 'package:tmail_ui_user/features/home/domain/state/get_session_state.dart'; import 'package:tmail_ui_user/features/labels/domain/state/create_new_label_state.dart'; -import 'package:tmail_ui_user/features/labels/domain/state/edit_label_state.dart'; import 'package:tmail_ui_user/features/labels/domain/state/delete_a_label_state.dart'; +import 'package:tmail_ui_user/features/labels/domain/state/edit_label_state.dart'; import 'package:tmail_ui_user/features/login/data/network/oidc_error.dart'; import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart'; import 'package:tmail_ui_user/features/login/domain/exceptions/oauth_authorization_error.dart'; @@ -133,9 +133,9 @@ class ToastManager { return '[${firstError.type.value}] ${firstError.description}'; } } else if (exception is ServerError) { - return '[${exception.error}] ${exception.errorDescription}'; + return '[${exception.error}] ${exception.message}'; } else if (exception is TemporarilyUnavailable) { - return '[${exception.error}] ${exception.errorDescription}'; + return '[${exception.error}] ${exception.message}'; } else if (exception is AutoRedirectToAppAfterStoreAuthorizeDestinationUrlException) { return ''; } diff --git a/model/lib/error_type_handler/account_exception.dart b/model/lib/error_type_handler/account_exception.dart index a2c6a2567..7c6c9b798 100644 --- a/model/lib/error_type_handler/account_exception.dart +++ b/model/lib/error_type_handler/account_exception.dart @@ -1,2 +1,8 @@ +import 'package:core/domain/exceptions/app_base_exception.dart'; -class NotFoundPersonalAccountException implements Exception {} \ No newline at end of file +class NotFoundPersonalAccountException extends AppBaseException { + const NotFoundPersonalAccountException([super.message]); + + @override + String get exceptionName => 'NotFoundPersonalAccountException'; +} diff --git a/model/lib/error_type_handler/unknown_address_exception.dart b/model/lib/error_type_handler/unknown_address_exception.dart index d6907c7ac..c726d8b9a 100644 --- a/model/lib/error_type_handler/unknown_address_exception.dart +++ b/model/lib/error_type_handler/unknown_address_exception.dart @@ -1 +1,8 @@ -class UnknownAddressException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class UnknownAddressException extends AppBaseException { + const UnknownAddressException([super.message]); + + @override + String get exceptionName => 'UnknownAddressException'; +} diff --git a/model/lib/error_type_handler/unknown_uri_exception.dart b/model/lib/error_type_handler/unknown_uri_exception.dart index d368dd831..f5a04b1cb 100644 --- a/model/lib/error_type_handler/unknown_uri_exception.dart +++ b/model/lib/error_type_handler/unknown_uri_exception.dart @@ -1 +1,8 @@ -class UnknownUriException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class UnknownUriException extends AppBaseException { + const UnknownUriException([super.message]); + + @override + String get exceptionName => 'UnknownUriException'; +} \ No newline at end of file diff --git a/model/lib/exceptions/token_oidc_exceptions.dart b/model/lib/exceptions/token_oidc_exceptions.dart index cbef3761e..5daec652c 100644 --- a/model/lib/exceptions/token_oidc_exceptions.dart +++ b/model/lib/exceptions/token_oidc_exceptions.dart @@ -1,7 +1,29 @@ -class AccessTokenIsNullException implements Exception {} +import 'package:core/domain/exceptions/app_base_exception.dart'; -class RefreshTokenIsNullException implements Exception {} +class AccessTokenIsNullException extends AppBaseException { + AccessTokenIsNullException([super.message]); -class TokenIdIsNullException implements Exception {} + @override + String get exceptionName => 'AccessTokenIsNullException'; +} -class ExpiresTimeIsNullException implements Exception {} +class RefreshTokenIsNullException extends AppBaseException { + RefreshTokenIsNullException([super.message]); + + @override + String get exceptionName => 'RefreshTokenIsNullException'; +} + +class TokenIdIsNullException extends AppBaseException { + TokenIdIsNullException([super.message]); + + @override + String get exceptionName => 'TokenIdIsNullException'; +} + +class ExpiresTimeIsNullException extends AppBaseException { + ExpiresTimeIsNullException([super.message]); + + @override + String get exceptionName => 'ExpiresTimeIsNullException'; +} diff --git a/model/lib/extensions/session_extension.dart b/model/lib/extensions/session_extension.dart index 20b9f7b8d..1617f8287 100644 --- a/model/lib/extensions/session_extension.dart +++ b/model/lib/extensions/session_extension.dart @@ -30,7 +30,7 @@ extension SessionExtension on Session { } else if (downloadUrl.hasOrigin) { downloadUrlValid = downloadUrl; } else { - throw UnknownUriException(); + throw const UnknownUriException(); } var baseUrl = '${downloadUrlValid.origin}${downloadUrlValid.path}?${downloadUrlValid.query}'; @@ -56,7 +56,7 @@ extension SessionExtension on Session { } else if (uploadUrl.hasOrigin) { uploadUrlValid = uploadUrl; } else { - throw UnknownUriException(); + throw const UnknownUriException(); } final baseUrl = '${uploadUrlValid.origin}${uploadUrlValid.path}'; @@ -109,7 +109,7 @@ extension SessionExtension on Session { return username.value.isEmail ? username.value : _getOwnEmailAddressFromPersonalAccount() ?? _getOwnEmailAddressFromPrincipalsCapability() - ?? (throw UnknownAddressException()); + ?? (throw const UnknownAddressException()); } String? _getOwnEmailAddressFromPersonalAccount() { @@ -168,7 +168,7 @@ extension SessionExtension on Session { return listPersonalAccount.first; } } - throw NotFoundPersonalAccountException(); + throw const NotFoundPersonalAccountException(); } AccountId get accountId => personalAccount.accountId; diff --git a/scribe/lib/scribe/ai/data/network/ai_api_exception.dart b/scribe/lib/scribe/ai/data/network/ai_api_exception.dart index f31f09e5c..fd78a4bb5 100644 --- a/scribe/lib/scribe/ai/data/network/ai_api_exception.dart +++ b/scribe/lib/scribe/ai/data/network/ai_api_exception.dart @@ -1,26 +1,39 @@ -class AIApiException implements Exception { - final String message; +import 'package:core/domain/exceptions/app_base_exception.dart'; + +class AIApiException extends AppBaseException { final int? statusCode; - AIApiException(this.message, {this.statusCode}); + const AIApiException(super.message, {this.statusCode}); + + @override + String get exceptionName => 'AIApiException'; @override String toString() { - if (statusCode != null) { - return 'AIApiException: $message (status code: $statusCode)'; - } - return 'AIApiException: $message'; + final statusPart = statusCode != null ? ' (status code: $statusCode)' : ''; + return '$exceptionName: $message$statusPart'; } } class AIApiNotAvailableException extends AIApiException { - AIApiNotAvailableException() : super('AI API is not available'); + const AIApiNotAvailableException() : super('AI API is not available'); + + @override + String get exceptionName => 'AIApiNotAvailableException'; } class AIApiEmptyResponseException extends AIApiException { - AIApiEmptyResponseException() : super('AI API returned empty response'); + const AIApiEmptyResponseException() : super('AI API returned empty response'); + + @override + String get exceptionName => 'AIApiEmptyResponseException'; } class GenerateAITextInteractorIsNotRegisteredException extends AIApiException { - GenerateAITextInteractorIsNotRegisteredException() : super('GenerateAITextInteractor is not registered'); -} \ No newline at end of file + const GenerateAITextInteractorIsNotRegisteredException() + : super('GenerateAITextInteractor is not registered'); + + @override + String get exceptionName => + 'GenerateAITextInteractorIsNotRegisteredException'; +} diff --git a/scribe/lib/scribe/ai/presentation/widgets/modal/ai_scribe_suggestion_widget.dart b/scribe/lib/scribe/ai/presentation/widgets/modal/ai_scribe_suggestion_widget.dart index 84389d372..7e2d753ff 100644 --- a/scribe/lib/scribe/ai/presentation/widgets/modal/ai_scribe_suggestion_widget.dart +++ b/scribe/lib/scribe/ai/presentation/widgets/modal/ai_scribe_suggestion_widget.dart @@ -50,7 +50,7 @@ class _AiScribeSuggestionWidgetState extends State { if (!Get.isRegistered()) { _state.value = dartz.Left( GenerateAITextFailure( - GenerateAITextInteractorIsNotRegisteredException(), + const GenerateAITextInteractorIsNotRegisteredException(), ), ); return; diff --git a/test/features/base/base_controller_test.dart b/test/features/base/base_controller_test.dart index 341e5cc24..af253bbd7 100644 --- a/test/features/base/base_controller_test.dart +++ b/test/features/base/base_controller_test.dart @@ -54,7 +54,10 @@ class MockBaseController extends BaseController { } } -class SomeOtherException extends RemoteException {} +class SomeOtherException extends RemoteException { + @override + String get exceptionName => 'SomeOtherException'; +} @GenerateNiceMocks([ MockSpec(),