-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Describe the bug
The application fails to gracefully handle HTTP connection errors (specifically DioException) when loading user data. The AuthenticationRemoteDataSourceImpl rethrows network errors, which propagate up through the UserRepository and LoadUserUseCase. The critical issue is in AuthBloc, where _loadUserUseCase() is called but not awaited or wrapped in a try-catch block, resulting in an unhandled exception that can crash the app or pause the debugger.
To Reproduce
Steps to reproduce the behavior:
- Set an invalid API URL in the
.envfile (or disconnect network to force a DNS/Connection error). - Launch the app.
- The app attempts to fetch the user profile via
AuthBloc. - Observe the
DioException(SocketException: Failed host lookup) in the logs/debugger. - The app may crash or enter an undefined state because the error is unhandled in
AuthBloc._appUserSubscriptionRequested.
Expected behavior
The application should catch network errors during the initial user load. It should either:
- Log the error silently and proceed if offline functionality is supported.
- Emit an error state to the UI to show a friendly message (e.g., "Connection failed").
- Retry the request gracefully.
Code Reference
In lib/presentation/app/bloc/auth/auth_bloc.dart:
Future<void> _appUserSubscriptionRequested(
AuthUserSubscriptionRequested event,
Emitter<AuthState> emit,
) {
_loadUserUseCase(); // <--- ERROR: Unawaited future with no error handling
return emit.onEach(
_streamUserUseCase.call(),
// ...Additional context
- Stack Trace:
DioException [connection error]: The connection errored: Failed host lookup: 'api.ontime.devkor.club' #0 DioMixin.request (package:dio/src/dio_mixin.dart:364:36) ... #4 LoadUserUseCase.call (package:on_time_front/domain/use-cases/load_user_use_case.dart:11:27) #5 AuthBloc._appUserSubscriptionRequested (package:on_time_front/presentation/app/bloc/auth/auth_bloc.dart:34:21) - Temporary Fix: Updating the API URL in
.envresolves the connection error, but the code remains vulnerable to future network failures.
Metadata
Metadata
Assignees
Labels
No labels