diff --git a/lib/features/base/mixin/handle_error_mixin.dart b/lib/features/base/mixin/handle_error_mixin.dart index 153bf7108..242cfdd96 100644 --- a/lib/features/base/mixin/handle_error_mixin.dart +++ b/lib/features/base/mixin/handle_error_mixin.dart @@ -1,5 +1,6 @@ import 'package:core/utils/app_logger.dart'; import 'package:dartz/dartz.dart'; +import 'package:jmap_dart_client/jmap/core/error/method/error_method_response.dart'; import 'package:jmap_dart_client/jmap/core/error/set_error.dart'; import 'package:jmap_dart_client/jmap/core/id.dart'; import 'package:jmap_dart_client/jmap/core/method/response/set_response.dart'; @@ -76,4 +77,26 @@ mixin HandleSetErrorMixin { logWarning('HandleSetErrorMixin::handleSetResponse():remainedErrors: $remainedErrors'); return remainedErrors; } + + parseErrorForSetResponse(SetResponse? response, Id requestId) { + final mapError = + response?.notCreated ?? response?.notUpdated ?? response?.notDestroyed; + if (mapError != null && mapError.containsKey(requestId)) { + final setError = mapError[requestId]; + log('HandleSetErrorMixin::parseErrorForSetResponse():setError: $setError'); + if (setError?.type == ErrorMethodResponse.invalidArguments) { + throw InvalidArgumentsMethodResponse( + description: setError?.description, + ); + } else if (setError?.type == ErrorMethodResponse.invalidResultReference) { + throw InvalidResultReferenceMethodResponse( + description: setError?.description, + ); + } else { + throw UnknownMethodResponse(description: setError?.description); + } + } else { + throw UnknownMethodResponse(); + } + } } diff --git a/lib/features/labels/data/datasource/label_datasource.dart b/lib/features/labels/data/datasource/label_datasource.dart index 49385740e..18e227e95 100644 --- a/lib/features/labels/data/datasource/label_datasource.dart +++ b/lib/features/labels/data/datasource/label_datasource.dart @@ -3,4 +3,6 @@ import 'package:labels/model/label.dart'; abstract class LabelDatasource { Future> getAllLabels(AccountId accountId); + + Future