Fix forward recipients error handling

This commit is contained in:
dab246
2025-08-26 00:50:03 +07:00
committed by Dat H. Pham
parent 5314116c76
commit cb9e38db44
15 changed files with 190 additions and 64 deletions
@@ -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();
}
}