fix: fix unimplemented error in listenable use case
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Malo Léon 2023-08-18 18:20:52 +02:00
parent 9704177c5a
commit a8e826f58b
4 changed files with 44 additions and 27 deletions

View File

@ -17,5 +17,10 @@
import 'package:wyatt_architecture/wyatt_architecture.dart';
class NotificationException extends AppException {
const NotificationException([super.message]);
const NotificationException([
super.message,
this.failure,
]);
final Error? failure;
}

View File

@ -0,0 +1,26 @@
// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/core/core.dart';
abstract final class AppExceptionHelper {
static AppException handleError(Object? error) => switch (error) {
AppException() => error,
Error() => NotificationException(error.toString(), error),
_ => ServerException(error.toString()),
};
}

View File

@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
import 'package:wyatt_architecture/wyatt_architecture.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/core/exceptions/notification_exeption.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/core/helpers/app_exception_helper.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/data_sources/remote/cloud_messaging_remote_data_source.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/entities/remote_notifications.dart';
import 'package:wyatt_cloud_messaging_bloc_base/src/domain/repositories/cloud_messaging_repository.dart';
@ -31,68 +31,52 @@ class CloudMessagingRepositoryImpl extends CloudMessagingRepository {
@override
FutureOrResult<String?> getToken() => Result.tryCatchAsync(
_notificationRemoteDataSource.getToken,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<void> subscribeToTopic(String topic) => Result.tryCatchAsync(
() => _notificationRemoteDataSource.subscribeToTopic(topic),
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<void> unsubscribeFromTopic(String topic) =>
Result.tryCatchAsync(
() => _notificationRemoteDataSource.unsubscribeFromTopic(topic),
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<void> requestPermissions() => Result.tryCatchAsync(
_notificationRemoteDataSource.requestPermissions,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<Stream<RemoteNotification>> onNotification() =>
Result.tryCatchAsync(
_notificationRemoteDataSource.onNotification,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<Stream<RemoteNotification>> onNotificationBackground() =>
Result.tryCatchAsync(
_notificationRemoteDataSource.onNotificationBackground,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<Stream<RemoteNotification>> onNotificationForeground() =>
Result.tryCatchAsync(
_notificationRemoteDataSource.onNotificationForeground,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
@override
FutureOrResult<void> init() => Result.tryCatchAsync(
_notificationRemoteDataSource.init,
(error) => error is AppException
? error
: NotificationException(error.toString()),
AppExceptionHelper.handleError,
);
}

View File

@ -40,7 +40,9 @@ class ListenNotificationUseCase
if (notificationStreamResponse.isOk) {
notificationStream = notificationStreamResponse.ok;
} else if (notificationStreamResponse.isErr) {
if (notificationStreamResponse.err! is UnimplementedError) {
if (notificationStreamResponse.err! is NotificationException &&
(notificationStreamResponse.err! as NotificationException).failure
is! UnimplementedError) {
return Err(notificationStreamResponse.err!);
}