refactor: Remove generic try-catch blocks and add explicit API error handling in activity places service.
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m41s
All checks were successful
Deploy Flutter to Firebase (Mac) / deploy-android (push) Successful in 3m41s
This commit is contained in:
@@ -174,7 +174,11 @@ class ActivityBloc extends Bloc<ActivityEvent, ActivityState> {
|
|||||||
'Erreur recherche activités: $e',
|
'Erreur recherche activités: $e',
|
||||||
stackTrace,
|
stackTrace,
|
||||||
);
|
);
|
||||||
emit(const ActivityError('Impossible de rechercher les activités'));
|
// Extraire le message d'erreur si disponible
|
||||||
|
final errorMessage = e.toString().replaceAll('Exception: ', '');
|
||||||
|
emit(
|
||||||
|
ActivityError('Impossible de rechercher les activités: $errorMessage'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ class ActivityPlacesService {
|
|||||||
int maxResults = 20,
|
int maxResults = 20,
|
||||||
int offset = 0,
|
int offset = 0,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
|
||||||
LoggerService.info(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)',
|
'ActivityPlacesService: Recherche d\'activités pour: $destination (max: $maxResults, offset: $offset)',
|
||||||
);
|
);
|
||||||
@@ -107,13 +106,6 @@ class ActivityPlacesService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return paginatedResults;
|
return paginatedResults;
|
||||||
} catch (e) {
|
|
||||||
LoggerService.error(
|
|
||||||
'ActivityPlacesService: Erreur lors de la recherche: $e',
|
|
||||||
);
|
|
||||||
_errorService.logError('activity_places_service', e);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Géocode une destination pour obtenir les coordonnées
|
/// Géocode une destination pour obtenir les coordonnées
|
||||||
@@ -191,7 +183,6 @@ class ActivityPlacesService {
|
|||||||
String tripId,
|
String tripId,
|
||||||
int radius,
|
int radius,
|
||||||
) async {
|
) async {
|
||||||
try {
|
|
||||||
final url =
|
final url =
|
||||||
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
||||||
'?location=$lat,$lng'
|
'?location=$lat,$lng'
|
||||||
@@ -226,15 +217,18 @@ class ActivityPlacesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return activities;
|
return activities;
|
||||||
}
|
} else if (data['status'] == 'ZERO_RESULTS') {
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
} catch (e) {
|
} else {
|
||||||
LoggerService.error(
|
LoggerService.error(
|
||||||
'ActivityPlacesService: Erreur recherche par catégorie: $e',
|
'ActivityPlacesService: Erreur API Places: ${data['status']} - ${data['error_message']}',
|
||||||
);
|
);
|
||||||
return [];
|
throw Exception(
|
||||||
|
'API Places Error: ${data['status']} - ${data['error_message']}',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Erreur HTTP ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -357,7 +351,6 @@ class ActivityPlacesService {
|
|||||||
required String tripId,
|
required String tripId,
|
||||||
int radius = 5000,
|
int radius = 5000,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
|
||||||
LoggerService.info(
|
LoggerService.info(
|
||||||
'ActivityPlacesService: Recherche textuelle: $query à $destination',
|
'ActivityPlacesService: Recherche textuelle: $query à $destination',
|
||||||
);
|
);
|
||||||
@@ -404,15 +397,16 @@ class ActivityPlacesService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return activities;
|
return activities;
|
||||||
}
|
} else if (data['status'] == 'ZERO_RESULTS') {
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
} catch (e) {
|
} else {
|
||||||
LoggerService.error(
|
LoggerService.error(
|
||||||
'ActivityPlacesService: Erreur recherche textuelle: $e',
|
'ActivityPlacesService: Erreur API Places Text Search: ${data['status']}',
|
||||||
);
|
);
|
||||||
return [];
|
throw Exception('API Error: ${data['status']}');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Erreur HTTP ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +517,6 @@ class ActivityPlacesService {
|
|||||||
int pageSize,
|
int pageSize,
|
||||||
String? nextPageToken,
|
String? nextPageToken,
|
||||||
) async {
|
) async {
|
||||||
try {
|
|
||||||
String url =
|
String url =
|
||||||
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
||||||
'?location=$lat,$lng'
|
'?location=$lat,$lng'
|
||||||
@@ -570,23 +563,17 @@ class ActivityPlacesService {
|
|||||||
'nextPageToken': data['next_page_token'],
|
'nextPageToken': data['next_page_token'],
|
||||||
'hasMoreData': data['next_page_token'] != null,
|
'hasMoreData': data['next_page_token'] != null,
|
||||||
};
|
};
|
||||||
}
|
} else if (data['status'] == 'ZERO_RESULTS') {
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
'activities': <Activity>[],
|
|
||||||
'nextPageToken': null,
|
|
||||||
'hasMoreData': false,
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
LoggerService.error(
|
|
||||||
'ActivityPlacesService: Erreur recherche catégorie paginée: $e',
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
'activities': <Activity>[],
|
'activities': <Activity>[],
|
||||||
'nextPageToken': null,
|
'nextPageToken': null,
|
||||||
'hasMoreData': false,
|
'hasMoreData': false,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
throw Exception('API Error: ${data['status']}');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Erreur HTTP ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,7 +586,6 @@ class ActivityPlacesService {
|
|||||||
int pageSize,
|
int pageSize,
|
||||||
String? nextPageToken,
|
String? nextPageToken,
|
||||||
) async {
|
) async {
|
||||||
try {
|
|
||||||
// Pour toutes les catégories, on utilise une recherche plus générale
|
// Pour toutes les catégories, on utilise une recherche plus générale
|
||||||
String url =
|
String url =
|
||||||
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
'https://maps.googleapis.com/maps/api/place/nearbysearch/json'
|
||||||
@@ -651,23 +637,17 @@ class ActivityPlacesService {
|
|||||||
'nextPageToken': data['next_page_token'],
|
'nextPageToken': data['next_page_token'],
|
||||||
'hasMoreData': data['next_page_token'] != null,
|
'hasMoreData': data['next_page_token'] != null,
|
||||||
};
|
};
|
||||||
}
|
} else if (data['status'] == 'ZERO_RESULTS') {
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
'activities': <Activity>[],
|
|
||||||
'nextPageToken': null,
|
|
||||||
'hasMoreData': false,
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
LoggerService.error(
|
|
||||||
'ActivityPlacesService: Erreur recherche toutes catégories paginée: $e',
|
|
||||||
);
|
|
||||||
return {
|
return {
|
||||||
'activities': <Activity>[],
|
'activities': <Activity>[],
|
||||||
'nextPageToken': null,
|
'nextPageToken': null,
|
||||||
'hasMoreData': false,
|
'hasMoreData': false,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
throw Exception('API Error: ${data['status']}');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw Exception('Erreur HTTP ${response.statusCode}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 1.0.3+1
|
version: 2025.12.1+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.9.2
|
sdk: ^3.9.2
|
||||||
|
|||||||
Reference in New Issue
Block a user