Skip to content

Commit 74935bf

Browse files
committed
fix(auth): improve anonymous auth error handling
- Added logging for unexpected errors - Improved error handling for exceptions - Replaced print statement with logger
1 parent 2ea1f83 commit 74935bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

routes/api/v1/auth/anonymous.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import 'package:dart_frog/dart_frog.dart';
44
import 'package:ht_api/src/helpers/response_helper.dart';
55
import 'package:ht_api/src/services/auth_service.dart';
66
import 'package:ht_shared/ht_shared.dart';
7+
import 'package:logging/logging.dart';
8+
9+
// Create a logger for this file.
10+
final _logger = Logger('anonymous_handler');
711

812
/// Handles POST requests to `/api/v1/auth/anonymous`.
913
///
@@ -37,9 +41,9 @@ Future<Response> onRequest(RequestContext context) async {
3741
} on HtHttpException catch (_) {
3842
// Let the central errorHandler middleware handle known exceptions
3943
rethrow;
40-
} catch (e) {
44+
} catch (e, s) {
4145
// Catch unexpected errors from the service layer
42-
print('Unexpected error in /anonymous handler: $e');
46+
_logger.severe('Unexpected error in /anonymous handler', e, s);
4347
// Let the central errorHandler handle this as a 500
4448
throw const OperationFailedException(
4549
'An unexpected error occurred during anonymous sign-in.',

0 commit comments

Comments
 (0)