@@ -69,27 +69,36 @@ class AccountBloc extends Bloc<AccountEvent, AccountState> {
69
69
AccountLoadContentPreferencesRequested event,
70
70
Emitter <AccountState > emit,
71
71
) async {
72
- emit (state.copyWith (status: AccountStatus .loading));
72
+ emit (state.copyWith (status: AccountStatus .loading)); // Indicate loading
73
73
try {
74
74
final preferences = await _userContentPreferencesRepository.read (
75
75
id: event.userId,
76
- userId: event.userId, // Preferences are user-scoped
76
+ userId: event.userId,
77
77
);
78
78
emit (
79
79
state.copyWith (status: AccountStatus .success, preferences: preferences),
80
80
);
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
82
89
emit (
83
90
state.copyWith (
84
91
status: AccountStatus .failure,
85
92
errorMessage: 'Failed to load preferences: ${e .message }' ,
93
+ preferences: null , // Ensure preferences are cleared on failure
86
94
),
87
95
);
88
- } catch (e) {
96
+ } catch (e) { // Catch-all for other unexpected errors
89
97
emit (
90
98
state.copyWith (
91
99
status: AccountStatus .failure,
92
100
errorMessage: 'An unexpected error occurred: $e ' ,
101
+ preferences: null , // Ensure preferences are cleared on failure
93
102
),
94
103
);
95
104
}
0 commit comments