Skip to content

Commit 205acd8

Browse files
committed
fix(auth): improve error handling in request-code handler
- Added logging for unexpected errors. - Improved error handling using Logger. - Replaced print statements with logging. - Catches and logs stack traces. - Uses HtHttpException for known exceptions.
1 parent 981e366 commit 205acd8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

routes/api/v1/auth/request-code.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import 'dart:io';
33
import 'package:dart_frog/dart_frog.dart';
44
import 'package:ht_api/src/services/auth_service.dart';
55
import 'package:ht_shared/ht_shared.dart'; // For exceptions
6+
import 'package:logging/logging.dart';
7+
8+
// Create a logger for this file.
9+
final _logger = Logger('request_code_handler');
610

711
/// Handles POST requests to `/api/v1/auth/request-code`.
812
///
@@ -79,9 +83,9 @@ Future<Response> onRequest(RequestContext context) async {
7983
} on HtHttpException catch (_) {
8084
// Let the central errorHandler middleware handle known exceptions
8185
rethrow;
82-
} catch (e) {
86+
} catch (e, s) {
8387
// Catch unexpected errors from the service layer
84-
print('Unexpected error in /request-code handler: $e');
88+
_logger.severe('Unexpected error in /request-code handler', e, s);
8589
// Let the central errorHandler handle this as a 500
8690
throw const OperationFailedException(
8791
'An unexpected error occurred while requesting the sign-in code.',

0 commit comments

Comments
 (0)