Skip to content

Commit 13a7cfb

Browse files
committed
fix(account): handle missing content preferences
- Handle NotFoundException explicitly - Provide default prefs when not found - Clear prefs on failure
1 parent 24b830f commit 13a7cfb

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/account/bloc/account_bloc.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,36 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
6969
AccountLoadContentPreferencesRequested event,
7070
Emitter<AccountState> emit,
7171
) async {
72-
emit(state.copyWith(status: AccountStatus.loading));
72+
emit(state.copyWith(status: AccountStatus.loading)); // Indicate loading
7373
try {
7474
final preferences = await _userContentPreferencesRepository.read(
7575
id: event.userId,
76-
userId: event.userId, // Preferences are user-scoped
76+
userId: event.userId,
7777
);
7878
emit(
7979
state.copyWith(status: AccountStatus.success, preferences: preferences),
8080
);
81-
} on HtHttpException catch (e) {
81+
} on NotFoundException { // Specifically handle NotFound
82+
emit(
83+
state.copyWith(
84+
status: AccountStatus.success, // It's a success, just no data
85+
preferences: UserContentPreferences(id: event.userId), // Provide default/empty
86+
),
87+
);
88+
} on HtHttpException catch (e) { // Handle other HTTP errors
8289
emit(
8390
state.copyWith(
8491
status: AccountStatus.failure,
8592
errorMessage: 'Failed to load preferences: ${e.message}',
93+
preferences: null, // Ensure preferences are cleared on failure
8694
),
8795
);
88-
} catch (e) {
96+
} catch (e) { // Catch-all for other unexpected errors
8997
emit(
9098
state.copyWith(
9199
status: AccountStatus.failure,
92100
errorMessage: 'An unexpected error occurred: $e',
101+
preferences: null, // Ensure preferences are cleared on failure
93102
),
94103
);
95104
}

0 commit comments

Comments
 (0)