refactoring
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@@ -21,6 +22,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
|
||||
final items = await _repository.getNotifications();
|
||||
emit(NotificationLoaded(items: items));
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationBloc: chargement notifications échoué', error: e, stackTrace: st);
|
||||
emit(NotificationError('Erreur de chargement: $e'));
|
||||
}
|
||||
@@ -46,6 +48,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
|
||||
}).toList();
|
||||
emit(NotificationLoaded(items: updatedItems));
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationBloc: marquer comme lu échoué', error: e, stackTrace: st);
|
||||
emit(NotificationError('Impossible de marquer comme lu'));
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
|
||||
final nonLues = notifications.where((n) => !n.estLue).length;
|
||||
emit(NotificationsLoaded(notifications: notifications, nonLuesCount: nonLues));
|
||||
} on DioException catch (e) {
|
||||
if (e.type == DioExceptionType.cancel) return;
|
||||
emit(NotificationsError(_networkError(e)));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(NotificationsError('Erreur lors du chargement : $e'));
|
||||
}
|
||||
}
|
||||
@@ -70,6 +72,7 @@ class NotificationsBloc extends Bloc<NotificationsEvent, NotificationsState> {
|
||||
emit(NotificationMarkedAsRead(notifications: updated, nonLuesCount: nonLues));
|
||||
}
|
||||
} catch (e, st) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
AppLogger.error('NotificationsBloc: marquer comme lu échoué', error: e, stackTrace: st);
|
||||
emit(NotificationsError('Impossible de marquer comme lu'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user