TF-3752 Better error handling when updating recipients in Forwarding
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import 'package:core/utils/app_logger.dart';
|
||||
import 'package:forward/forward/forward_id.dart';
|
||||
import 'package:forward/forward/get/get_forward_method.dart';
|
||||
import 'package:forward/forward/get/get_forward_response.dart';
|
||||
import 'package:forward/forward/set/set_forward_method.dart';
|
||||
import 'package:forward/forward/set/set_forward_response.dart';
|
||||
import 'package:forward/forward/tmail_forward.dart';
|
||||
import 'package:jmap_dart_client/http/http_client.dart';
|
||||
import 'package:jmap_dart_client/jmap/account_id.dart';
|
||||
import 'package:jmap_dart_client/jmap/jmap_request.dart';
|
||||
import 'package:tmail_ui_user/features/base/mixin/handle_error_mixin.dart';
|
||||
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
|
||||
import 'package:tmail_ui_user/features/manage_account/domain/exceptions/forward_exception.dart';
|
||||
|
||||
class ForwardingAPI {
|
||||
class ForwardingAPI with HandleSetErrorMixin {
|
||||
final HttpClient _httpClient;
|
||||
|
||||
ForwardingAPI(this._httpClient);
|
||||
@@ -31,7 +35,7 @@ class ForwardingAPI {
|
||||
getForwardInvocation.methodCallId,
|
||||
GetForwardResponse.deserialize);
|
||||
|
||||
final tMailForwardResult = result?.list.first;
|
||||
final tMailForwardResult = result?.list.firstOrNull;
|
||||
if (tMailForwardResult == null) {
|
||||
throw NotFoundForwardException();
|
||||
}
|
||||
@@ -40,14 +44,15 @@ class ForwardingAPI {
|
||||
}
|
||||
|
||||
Future<TMailForward> updateForward(AccountId accountId, TMailForward forward) async {
|
||||
log('ForwardingAPI::updateForward: ${forward.toJson()}');
|
||||
final setForwardMethod = SetForwardMethod(accountId)
|
||||
..addUpdatesSingleton({
|
||||
ForwardIdSingleton.forwardIdSingleton.id : forward
|
||||
});
|
||||
|
||||
final processingInvocation = ProcessingInvocation();
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation)
|
||||
..invocation(setForwardMethod);
|
||||
final requestBuilder = JmapRequestBuilder(_httpClient, processingInvocation);
|
||||
final setForwardInvocation = requestBuilder.invocation(setForwardMethod);
|
||||
|
||||
final getForwardMethod = GetForwardMethod(accountId)
|
||||
..addIds({ForwardIdSingleton.forwardIdSingleton.id});
|
||||
@@ -58,11 +63,27 @@ class ForwardingAPI {
|
||||
.build()
|
||||
.execute();
|
||||
|
||||
final setForwardResponse = response.parse<SetForwardResponse>(
|
||||
setForwardInvocation.methodCallId,
|
||||
SetForwardResponse.deserialize,
|
||||
);
|
||||
|
||||
final mapErrors = handleSetResponse([setForwardResponse]);
|
||||
if (mapErrors.isNotEmpty) {
|
||||
throw SetMethodException(mapErrors);
|
||||
}
|
||||
|
||||
final updatedForward = setForwardResponse?.updated;
|
||||
if (updatedForward?.isNotEmpty != true) {
|
||||
throw UpdateForwardException();
|
||||
}
|
||||
|
||||
final getForwardResponse = response.parse<GetForwardResponse>(
|
||||
getForwardInvocation.methodCallId,
|
||||
GetForwardResponse.deserialize);
|
||||
GetForwardResponse.deserialize,
|
||||
);
|
||||
|
||||
final newForward = getForwardResponse?.list.first;
|
||||
final newForward = getForwardResponse?.list.firstOrNull;
|
||||
if (newForward == null) {
|
||||
throw NotFoundForwardException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user