feat: Implement centralized error handling with ErrorService; replace print statements with logging in services and blocs
feat: Add ErrorContent widget for displaying error messages in dialogs and bottom sheets refactor: Update GroupBloc and GroupRepository to utilize ErrorService for error logging refactor: Enhance user and trip services to log errors using ErrorService refactor: Clean up debug print statements in GroupContent and related components
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:travel_mate/services/error_service.dart';
|
||||
import 'group_event.dart';
|
||||
import 'group_state.dart';
|
||||
import '../../repositories/group_repository.dart';
|
||||
@@ -8,6 +9,7 @@ import '../../data/models/group.dart';
|
||||
class GroupBloc extends Bloc<GroupEvent, GroupState> {
|
||||
final GroupRepository _repository;
|
||||
StreamSubscription? _groupsSubscription;
|
||||
final _errorService = ErrorService();
|
||||
|
||||
GroupBloc(this._repository) : super(GroupInitial()) {
|
||||
on<LoadGroupsByUserId>(_onLoadGroupsByUserId);
|
||||
@@ -24,33 +26,20 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
|
||||
Future<void> _onLoadGroupsByUserId(
|
||||
LoadGroupsByUserId event,
|
||||
Emitter<GroupState> emit,
|
||||
) async {
|
||||
print('===== GroupBloc: _onLoadGroupsByUserId START =====');
|
||||
|
||||
) async {
|
||||
try {
|
||||
emit(GroupLoading());
|
||||
print('>>> GroupBloc: État GroupLoading émis');
|
||||
|
||||
await _groupsSubscription?.cancel();
|
||||
print('>>> GroupBloc: Ancien subscription annulé');
|
||||
|
||||
_groupsSubscription = _repository.getGroupsByUserId(event.userId).listen(
|
||||
(groups) {
|
||||
print('===== GroupBloc: Stream reçu ${groups.length} groupes =====');
|
||||
// Utiliser un événement interne au lieu d'émettre directement
|
||||
add(_GroupsUpdated(groups));
|
||||
},
|
||||
onError: (error) {
|
||||
print('===== GroupBloc: Erreur stream: $error =====');
|
||||
add(_GroupsUpdated([], error: error.toString()));
|
||||
},
|
||||
);
|
||||
|
||||
print('>>> GroupBloc: Subscription créé avec succès');
|
||||
} catch (e, stackTrace) {
|
||||
print('===== GroupBloc: Exception _onLoadGroupsByUserId =====');
|
||||
print('Exception: $e');
|
||||
print('StackTrace: $stackTrace');
|
||||
_errorService.logError(e.toString(), stackTrace);
|
||||
emit(GroupError(e.toString()));
|
||||
}
|
||||
}
|
||||
@@ -60,16 +49,11 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
|
||||
_GroupsUpdated event,
|
||||
Emitter<GroupState> emit,
|
||||
) async {
|
||||
print('===== GroupBloc: _onGroupsUpdated =====');
|
||||
print('Groupes reçus: ${event.groups.length}');
|
||||
|
||||
if (event.error != null) {
|
||||
print('>>> Émission GroupError: ${event.error}');
|
||||
_errorService.logError(event.error!, StackTrace.current);
|
||||
emit(GroupError(event.error!));
|
||||
} else {
|
||||
print('>>> Émission GroupsLoaded avec ${event.groups.length} groupes');
|
||||
emit(GroupsLoaded(event.groups));
|
||||
print('>>> GroupsLoaded émis avec succès !');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +156,6 @@ class GroupBloc extends Bloc<GroupEvent, GroupState> {
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
print('===== GroupBloc: close() =====');
|
||||
_groupsSubscription?.cancel();
|
||||
return super.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user