TF-2907 Handle error correctly when perform reply event action

This commit is contained in:
dab246
2024-07-09 19:52:38 +07:00
committed by Dat H. Pham
parent 9bdb327c9e
commit 0a8a0b0a6d
3 changed files with 45 additions and 9 deletions
@@ -74,7 +74,11 @@ class CalendarEventAPI {
throw NotAcceptableCalendarEventException(); throw NotAcceptableCalendarEventException();
} }
return calendarEventAcceptResponse; if (calendarEventAcceptResponse.accepted?.isNotEmpty == true) {
return calendarEventAcceptResponse;
} else {
throw CannotReplyCalendarEventException(mapErrors: calendarEventAcceptResponse.notAccepted);
}
} }
Future<CalendarEventMaybeResponse> maybeEventInvitation( Future<CalendarEventMaybeResponse> maybeEventInvitation(
@@ -102,7 +106,11 @@ class CalendarEventAPI {
throw NotMaybeableCalendarEventException(); throw NotMaybeableCalendarEventException();
} }
return calendarEventMaybeResponse; if (calendarEventMaybeResponse.maybe?.isNotEmpty == true) {
return calendarEventMaybeResponse;
} else {
throw CannotReplyCalendarEventException(mapErrors: calendarEventMaybeResponse.notMaybe);
}
} }
Future<CalendarEventRejectResponse> rejectEventInvitation( Future<CalendarEventRejectResponse> rejectEventInvitation(
@@ -130,6 +138,10 @@ class CalendarEventAPI {
throw NotRejectableCalendarEventException(); throw NotRejectableCalendarEventException();
} }
return calendarEventRejectResponse; if (calendarEventRejectResponse.rejected?.isNotEmpty == true) {
return calendarEventRejectResponse;
} else {
throw CannotReplyCalendarEventException(mapErrors: calendarEventRejectResponse.notRejected);
}
} }
} }
@@ -1,4 +1,7 @@
import 'package:jmap_dart_client/jmap/core/error/set_error.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
class NotFoundCalendarEventException implements Exception {} class NotFoundCalendarEventException implements Exception {}
class NotParsableCalendarEventException implements Exception {} class NotParsableCalendarEventException implements Exception {}
@@ -8,3 +11,9 @@ class NotAcceptableCalendarEventException implements Exception {}
class NotMaybeableCalendarEventException implements Exception {} class NotMaybeableCalendarEventException implements Exception {}
class NotRejectableCalendarEventException implements Exception {} class NotRejectableCalendarEventException implements Exception {}
class CannotReplyCalendarEventException implements Exception {
final Map<Id, SetError>? mapErrors;
CannotReplyCalendarEventException({this.mapErrors});
}
@@ -32,6 +32,7 @@ import 'package:tmail_ui_user/features/base/mixin/app_loader_mixin.dart';
import 'package:tmail_ui_user/features/base/state/button_state.dart'; import 'package:tmail_ui_user/features/base/state/button_state.dart';
import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart'; import 'package:tmail_ui_user/features/composer/presentation/extensions/email_action_type_extension.dart';
import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart'; import 'package:tmail_ui_user/features/destination_picker/presentation/model/destination_picker_arguments.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/calendar_event_exceptions.dart';
import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart'; import 'package:tmail_ui_user/features/email/domain/exceptions/email_exceptions.dart';
import 'package:tmail_ui_user/features/email/domain/extensions/list_attachments_extension.dart'; import 'package:tmail_ui_user/features/email/domain/extensions/list_attachments_extension.dart';
import 'package:tmail_ui_user/features/email/domain/model/detailed_email.dart'; import 'package:tmail_ui_user/features/email/domain/model/detailed_email.dart';
@@ -255,7 +256,7 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
_showMessageWhenEmailPrintingFailed(failure); _showMessageWhenEmailPrintingFailed(failure);
} else if (failure is CalendarEventReplyFailure } else if (failure is CalendarEventReplyFailure
|| failure is StoreEventAttendanceStatusFailure) { || failure is StoreEventAttendanceStatusFailure) {
_calendarEventFailure(); _calendarEventFailure(failure);
} }
} }
@@ -1752,12 +1753,26 @@ class SingleEmailController extends BaseController with AppLoaderMixin {
success.eventActionType.getToastMessageSuccess(currentContext!)); success.eventActionType.getToastMessageSuccess(currentContext!));
} }
void _calendarEventFailure() { void _calendarEventFailure(Failure failure) {
if (currentOverlayContext != null && currentContext != null) { if (currentOverlayContext == null || currentContext == null) {
appToast.showToastErrorMessage( return;
currentOverlayContext!,
AppLocalizations.of(currentContext!).eventReplyWasSentUnsuccessfully);
} }
if (failure is CalendarEventReplyFailure && failure.exception is CannotReplyCalendarEventException) {
final replyEventException = failure.exception as CannotReplyCalendarEventException;
if (replyEventException.mapErrors?.isNotEmpty == true) {
appToast.showToastErrorMessage(
currentOverlayContext!,
replyEventException.mapErrors!.values.first.description
?? AppLocalizations.of(currentContext!).eventReplyWasSentUnsuccessfully);
return;
}
}
appToast.showToastErrorMessage(
currentOverlayContext!,
AppLocalizations.of(currentContext!).eventReplyWasSentUnsuccessfully);
} }
void _downloadMessageAsEML(PresentationEmail presentationEmail) { void _downloadMessageAsEML(PresentationEmail presentationEmail) {