@@ -3,17 +3,7 @@ import 'dart:async';
3
3
import 'package:bloc/bloc.dart' ;
4
4
import 'package:equatable/equatable.dart' ;
5
5
import 'package:ht_auth_repository/ht_auth_repository.dart' ;
6
- import 'package:ht_shared/ht_shared.dart' show
7
- AuthenticationException,
8
- ForbiddenException,
9
- HtHttpException,
10
- InvalidInputException,
11
- NetworkException,
12
- NotFoundException,
13
- OperationFailedException,
14
- ServerException,
15
- UnauthorizedException,
16
- User;
6
+ import 'package:ht_shared/ht_shared.dart' show AuthenticationException, ForbiddenException, HtHttpException, InvalidInputException, NetworkException, NotFoundException, OperationFailedException, ServerException, UnauthorizedException, UnknownException, User;
17
7
18
8
part 'authentication_event.dart' ;
19
9
part 'authentication_state.dart' ;
@@ -70,16 +60,6 @@ class AuthenticationBloc
70
60
AuthenticationRequestSignInCodeRequested event,
71
61
Emitter <AuthenticationState > emit,
72
62
) async {
73
- // Validate email format (basic check)
74
- if (event.email.isEmpty || ! event.email.contains ('@' )) {
75
- emit (
76
- state.copyWith (
77
- status: AuthenticationStatus .failure,
78
- errorMessage: 'Please enter a valid email address.' ,
79
- ),
80
- );
81
- return ;
82
- }
83
63
emit (state.copyWith (status: AuthenticationStatus .requestCodeLoading));
84
64
try {
85
65
await _authenticationRepository.requestSignInCode (
@@ -96,61 +76,58 @@ class AuthenticationBloc
96
76
emit (
97
77
state.copyWith (
98
78
status: AuthenticationStatus .failure,
99
- errorMessage : 'Invalid input: ${ e . message }' ,
79
+ exception : e ,
100
80
),
101
81
);
102
82
} on UnauthorizedException catch (e) {
103
83
emit (
104
84
state.copyWith (
105
85
status: AuthenticationStatus .failure,
106
- errorMessage : e.message ,
86
+ exception : e,
107
87
),
108
88
);
109
89
} on ForbiddenException catch (e) {
110
90
emit (
111
91
state.copyWith (
112
92
status: AuthenticationStatus .failure,
113
- errorMessage : e.message ,
93
+ exception : e,
114
94
),
115
95
);
116
- } on NetworkException catch (_ ) {
96
+ } on NetworkException catch (e ) {
117
97
emit (
118
98
state.copyWith (
119
99
status: AuthenticationStatus .failure,
120
- errorMessage : 'Network error occurred.' ,
100
+ exception : e ,
121
101
),
122
102
);
123
103
} on ServerException catch (e) {
124
104
emit (
125
105
state.copyWith (
126
106
status: AuthenticationStatus .failure,
127
- errorMessage : 'Server error: ${ e . message }' ,
107
+ exception : e ,
128
108
),
129
109
);
130
110
} on OperationFailedException catch (e) {
131
111
emit (
132
112
state.copyWith (
133
113
status: AuthenticationStatus .failure,
134
- errorMessage : 'Operation failed: ${ e . message }' ,
114
+ exception : e ,
135
115
),
136
116
);
137
117
} on HtHttpException catch (e) {
138
118
// Catch any other HtHttpException subtypes
139
- final message = e.message.isNotEmpty
140
- ? e.message
141
- : 'An unspecified HTTP error occurred.' ;
142
119
emit (
143
120
state.copyWith (
144
121
status: AuthenticationStatus .failure,
145
- errorMessage : 'HTTP error: $ message ' ,
122
+ exception : e ,
146
123
),
147
124
);
148
125
} catch (e) {
149
126
// Catch any other unexpected errors
150
127
emit (
151
128
state.copyWith (
152
129
status: AuthenticationStatus .failure,
153
- errorMessage : 'An unexpected error occurred: $e ' ,
130
+ exception : UnknownException ( 'An unexpected error occurred: $e ' ) ,
154
131
),
155
132
);
156
133
// Optionally log the stackTrace here
@@ -175,58 +152,58 @@ class AuthenticationBloc
175
152
emit (
176
153
state.copyWith (
177
154
status: AuthenticationStatus .failure,
178
- errorMessage : e.message ,
155
+ exception : e,
179
156
),
180
157
);
181
158
} on AuthenticationException catch (e) {
182
159
emit (
183
160
state.copyWith (
184
161
status: AuthenticationStatus .failure,
185
- errorMessage : e.message ,
162
+ exception : e,
186
163
),
187
164
);
188
165
} on NotFoundException catch (e) {
189
166
emit (
190
167
state.copyWith (
191
168
status: AuthenticationStatus .failure,
192
- errorMessage : e.message ,
169
+ exception : e,
193
170
),
194
171
);
195
- } on NetworkException catch (_ ) {
172
+ } on NetworkException catch (e ) {
196
173
emit (
197
174
state.copyWith (
198
175
status: AuthenticationStatus .failure,
199
- errorMessage : 'Network error occurred.' ,
176
+ exception : e ,
200
177
),
201
178
);
202
179
} on ServerException catch (e) {
203
180
emit (
204
181
state.copyWith (
205
182
status: AuthenticationStatus .failure,
206
- errorMessage : 'Server error: ${ e . message }' ,
183
+ exception : e ,
207
184
),
208
185
);
209
186
} on OperationFailedException catch (e) {
210
187
emit (
211
188
state.copyWith (
212
189
status: AuthenticationStatus .failure,
213
- errorMessage : 'Operation failed: ${ e . message }' ,
190
+ exception : e ,
214
191
),
215
192
);
216
193
} on HtHttpException catch (e) {
217
194
// Catch any other HtHttpException subtypes
218
195
emit (
219
196
state.copyWith (
220
197
status: AuthenticationStatus .failure,
221
- errorMessage : 'HTTP error: ${ e . message }' ,
198
+ exception : e ,
222
199
),
223
200
);
224
201
} catch (e) {
225
202
// Catch any other unexpected errors
226
203
emit (
227
204
state.copyWith (
228
205
status: AuthenticationStatus .failure,
229
- errorMessage : 'An unexpected error occurred: $e ' ,
206
+ exception : UnknownException ( 'An unexpected error occurred: $e ' ) ,
230
207
),
231
208
);
232
209
// Optionally log the stackTrace here
@@ -243,40 +220,40 @@ class AuthenticationBloc
243
220
await _authenticationRepository.signOut ();
244
221
// On success, the _AuthenticationStatusChanged listener will handle
245
222
// emitting AuthenticationUnauthenticated.
246
- } on NetworkException catch (_ ) {
223
+ } on NetworkException catch (e ) {
247
224
emit (
248
225
state.copyWith (
249
226
status: AuthenticationStatus .failure,
250
- errorMessage : 'Network error occurred.' ,
227
+ exception : e ,
251
228
),
252
229
);
253
230
} on ServerException catch (e) {
254
231
emit (
255
232
state.copyWith (
256
233
status: AuthenticationStatus .failure,
257
- errorMessage : 'Server error: ${ e . message }' ,
234
+ exception : e ,
258
235
),
259
236
);
260
237
} on OperationFailedException catch (e) {
261
238
emit (
262
239
state.copyWith (
263
240
status: AuthenticationStatus .failure,
264
- errorMessage : 'Operation failed: ${ e . message }' ,
241
+ exception : e ,
265
242
),
266
243
);
267
244
} on HtHttpException catch (e) {
268
245
// Catch any other HtHttpException subtypes
269
246
emit (
270
247
state.copyWith (
271
248
status: AuthenticationStatus .failure,
272
- errorMessage : 'HTTP error: ${ e . message }' ,
249
+ exception : e ,
273
250
),
274
251
);
275
252
} catch (e) {
276
253
emit (
277
254
state.copyWith (
278
255
status: AuthenticationStatus .failure,
279
- errorMessage : 'An unexpected error occurred: $e ' ,
256
+ exception : UnknownException ( 'An unexpected error occurred: $e ' ) ,
280
257
),
281
258
);
282
259
}
0 commit comments