Skip to content

Commit 4cca6a5

Browse files
committed
fix(content-management): improve error handling in blocs
- Replaced errorMessage with exception in states - Improved error handling in CreateSourceBloc - Improved error handling in EditTopicBloc - Updated exception handling for better clarity - Used HtHttpException for specific error types
1 parent c2e2cb4 commit 4cca6a5

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

lib/content_management/bloc/create_source/create_source_bloc.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
5151
emit(
5252
state.copyWith(
5353
status: CreateSourceStatus.failure,
54-
errorMessage: e.message,
54+
exception: e,
5555
),
5656
);
5757
} catch (e) {
5858
emit(
5959
state.copyWith(
6060
status: CreateSourceStatus.failure,
61-
errorMessage: e.toString(),
61+
exception: UnknownException('An unexpected error occurred: $e'),
6262
),
6363
);
6464
}
@@ -151,14 +151,14 @@ class CreateSourceBloc extends Bloc<CreateSourceEvent, CreateSourceState> {
151151
emit(
152152
state.copyWith(
153153
status: CreateSourceStatus.failure,
154-
errorMessage: e.message,
154+
exception: e,
155155
),
156156
);
157157
} catch (e) {
158158
emit(
159159
state.copyWith(
160160
status: CreateSourceStatus.failure,
161-
errorMessage: e.toString(),
161+
exception: UnknownException('An unexpected error occurred: $e'),
162162
),
163163
);
164164
}

lib/content_management/bloc/edit_topic/edit_topic_bloc.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class EditTopicBloc extends Bloc<EditTopicEvent, EditTopicState> {
4747
emit(
4848
state.copyWith(
4949
status: EditTopicStatus.failure,
50-
errorMessage: e.message,
50+
exception: e,
5151
),
5252
);
5353
} catch (e) {
5454
emit(
5555
state.copyWith(
5656
status: EditTopicStatus.failure,
57-
errorMessage: e.toString(),
57+
exception: UnknownException('An unexpected error occurred: $e'),
5858
),
5959
);
6060
}
@@ -121,7 +121,7 @@ class EditTopicBloc extends Bloc<EditTopicEvent, EditTopicState> {
121121
emit(
122122
state.copyWith(
123123
status: EditTopicStatus.failure,
124-
errorMessage: 'Cannot update: Original topic data not loaded.',
124+
exception: UnknownException('Cannot update: Original topic data not loaded.'),
125125
),
126126
);
127127
return;
@@ -152,14 +152,14 @@ class EditTopicBloc extends Bloc<EditTopicEvent, EditTopicState> {
152152
emit(
153153
state.copyWith(
154154
status: EditTopicStatus.failure,
155-
errorMessage: e.message,
155+
exception: e,
156156
),
157157
);
158158
} catch (e) {
159159
emit(
160160
state.copyWith(
161161
status: EditTopicStatus.failure,
162-
errorMessage: e.toString(),
162+
exception: UnknownException('An unexpected error occurred: $e'),
163163
),
164164
);
165165
}

lib/content_management/bloc/edit_topic/edit_topic_state.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class EditTopicState extends Equatable {
2727
this.description = '',
2828
this.iconUrl = '',
2929
this.contentStatus = ContentStatus.active,
30-
this.errorMessage,
30+
this.exception,
3131
this.updatedTopic,
3232
});
3333

@@ -37,7 +37,7 @@ final class EditTopicState extends Equatable {
3737
final String description;
3838
final String iconUrl;
3939
final ContentStatus contentStatus;
40-
final String? errorMessage;
40+
final HtHttpException? exception;
4141
final Topic? updatedTopic;
4242

4343
/// Returns true if the form is valid and can be submitted.
@@ -52,7 +52,7 @@ final class EditTopicState extends Equatable {
5252
String? description,
5353
String? iconUrl,
5454
ContentStatus? contentStatus,
55-
String? errorMessage,
55+
HtHttpException? exception,
5656
Topic? updatedTopic,
5757
}) {
5858
return EditTopicState(
@@ -62,7 +62,7 @@ final class EditTopicState extends Equatable {
6262
description: description ?? this.description,
6363
iconUrl: iconUrl ?? this.iconUrl,
6464
contentStatus: contentStatus ?? this.contentStatus,
65-
errorMessage: errorMessage ?? this.errorMessage,
65+
exception: exception,
6666
updatedTopic: updatedTopic ?? this.updatedTopic,
6767
);
6868
}
@@ -75,7 +75,7 @@ final class EditTopicState extends Equatable {
7575
description,
7676
iconUrl,
7777
contentStatus,
78-
errorMessage,
78+
exception,
7979
updatedTopic,
8080
];
8181
}

0 commit comments

Comments
 (0)