Fix forward recipients error handling
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:forward/forward/tmail_forward.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/add_recipients_in_forwarding_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/delete_recipient_in_forwarding_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/edit_local_copy_in_forwarding_request.dart';
|
||||
@@ -7,9 +8,18 @@ import 'package:tmail_ui_user/features/manage_account/domain/model/edit_local_co
|
||||
abstract class ForwardingDataSource {
|
||||
Future<TMailForward> getForward(AccountId accountId);
|
||||
|
||||
Future<TMailForward> deleteRecipientInForwarding(AccountId accountId, DeleteRecipientInForwardingRequest deleteRequest);
|
||||
Future<(TMailForward, SetMethodException?)> deleteRecipientInForwarding(
|
||||
AccountId accountId,
|
||||
DeleteRecipientInForwardingRequest deleteRequest,
|
||||
);
|
||||
|
||||
Future<TMailForward> addRecipientsInForwarding(AccountId accountId, AddRecipientInForwardingRequest addRequest);
|
||||
Future<(TMailForward, SetMethodException?)> addRecipientsInForwarding(
|
||||
AccountId accountId,
|
||||
AddRecipientInForwardingRequest addRequest,
|
||||
);
|
||||
|
||||
Future<TMailForward> editLocalCopyInForwarding(AccountId accountId, EditLocalCopyInForwardingRequest editRequest);
|
||||
Future<(TMailForward, SetMethodException?)> editLocalCopyInForwarding(
|
||||
AccountId accountId,
|
||||
EditLocalCopyInForwardingRequest editRequest,
|
||||
);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:forward/forward/tmail_forward.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/datasource/forwarding_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/network/forwarding_api.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/add_recipients_in_forwarding_request.dart';
|
||||
@@ -22,23 +23,41 @@ class ForwardingDataSourceImpl extends ForwardingDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TMailForward> deleteRecipientInForwarding(AccountId accountId, DeleteRecipientInForwardingRequest deleteRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> deleteRecipientInForwarding(
|
||||
AccountId accountId,
|
||||
DeleteRecipientInForwardingRequest deleteRequest,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await _forwardingAPI.updateForward(accountId, deleteRequest.newTMailForward);
|
||||
return await _forwardingAPI.updateForward(
|
||||
accountId,
|
||||
deleteRequest.newTMailForward,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TMailForward> addRecipientsInForwarding(AccountId accountId, AddRecipientInForwardingRequest addRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> addRecipientsInForwarding(
|
||||
AccountId accountId,
|
||||
AddRecipientInForwardingRequest addRequest,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await _forwardingAPI.updateForward(accountId, addRequest.newTMailForward);
|
||||
return await _forwardingAPI.updateForward(
|
||||
accountId,
|
||||
addRequest.newTMailForward,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TMailForward> editLocalCopyInForwarding(AccountId accountId, EditLocalCopyInForwardingRequest editRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> editLocalCopyInForwarding(
|
||||
AccountId accountId,
|
||||
EditLocalCopyInForwardingRequest editRequest,
|
||||
) {
|
||||
return Future.sync(() async {
|
||||
return await _forwardingAPI.updateForward(accountId, editRequest.newTMailForward);
|
||||
return await _forwardingAPI.updateForward(
|
||||
accountId,
|
||||
editRequest.newTMailForward,
|
||||
);
|
||||
}).catchError(_exceptionThrower.throwException);
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,10 @@ class ForwardingAPI with HandleSetErrorMixin {
|
||||
return tMailForwardResult;
|
||||
}
|
||||
|
||||
Future<TMailForward> updateForward(AccountId accountId, TMailForward forward) async {
|
||||
Future<(TMailForward, SetMethodException?)> updateForward(
|
||||
AccountId accountId,
|
||||
TMailForward forward,
|
||||
) async {
|
||||
log('ForwardingAPI::updateForward: ${forward.toJson()}');
|
||||
final setForwardMethod = SetForwardMethod(accountId)
|
||||
..addUpdatesSingleton({
|
||||
@@ -69,14 +72,9 @@ class ForwardingAPI with HandleSetErrorMixin {
|
||||
);
|
||||
|
||||
final mapErrors = handleSetResponse([setForwardResponse]);
|
||||
if (mapErrors.isNotEmpty) {
|
||||
throw SetMethodException(mapErrors);
|
||||
}
|
||||
|
||||
final updatedForward = setForwardResponse?.updated;
|
||||
if (updatedForward?.isNotEmpty != true) {
|
||||
throw UpdateForwardException();
|
||||
}
|
||||
final methodException = mapErrors.isNotEmpty
|
||||
? SetMethodException(mapErrors)
|
||||
: null;
|
||||
|
||||
final getForwardResponse = response.parse<GetForwardResponse>(
|
||||
getForwardInvocation.methodCallId,
|
||||
@@ -84,10 +82,10 @@ class ForwardingAPI with HandleSetErrorMixin {
|
||||
);
|
||||
|
||||
final newForward = getForwardResponse?.list.firstOrNull;
|
||||
if (newForward == null) {
|
||||
throw NotFoundForwardException();
|
||||
if (newForward != null) {
|
||||
return (newForward, methodException);
|
||||
}
|
||||
|
||||
return newForward;
|
||||
throw methodException ?? NotFoundForwardException();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:forward/forward/tmail_forward.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/data/datasource/forwarding_datasource.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/add_recipients_in_forwarding_request.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/model/delete_recipient_in_forwarding_request.dart';
|
||||
@@ -12,17 +13,26 @@ class ForwardingRepositoryImpl extends ForwardingRepository {
|
||||
ForwardingRepositoryImpl(this.dataSource);
|
||||
|
||||
@override
|
||||
Future<TMailForward> addRecipientsInForwarding(AccountId accountId, AddRecipientInForwardingRequest addRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> addRecipientsInForwarding(
|
||||
AccountId accountId,
|
||||
AddRecipientInForwardingRequest addRequest,
|
||||
) {
|
||||
return dataSource.addRecipientsInForwarding(accountId, addRequest);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TMailForward> deleteRecipientInForwarding(AccountId accountId, DeleteRecipientInForwardingRequest deleteRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> deleteRecipientInForwarding(
|
||||
AccountId accountId,
|
||||
DeleteRecipientInForwardingRequest deleteRequest,
|
||||
) {
|
||||
return dataSource.deleteRecipientInForwarding(accountId, deleteRequest);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<TMailForward> editLocalCopyInForwarding(AccountId accountId, EditLocalCopyInForwardingRequest editRequest) {
|
||||
Future<(TMailForward, SetMethodException?)> editLocalCopyInForwarding(
|
||||
AccountId accountId,
|
||||
EditLocalCopyInForwardingRequest editRequest,
|
||||
) {
|
||||
return dataSource.editLocalCopyInForwarding(accountId, editRequest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user