Skip to content

Commit ee01c85

Browse files
committed
fix(auth): improve sign-out error logging
- Replaced `print` statements with logger. - Added stack traces to error logs. - Improved error message clarity. - Used structured logging for better analysis.
1 parent 205acd8 commit ee01c85

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

routes/api/v1/auth/sign-out.dart

Lines changed: 12 additions & 4 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 User and exceptions
6+
import 'package:logging/logging.dart';
7+
8+
// Create a logger for this file.
9+
final _logger = Logger('sign_out_handler');
610

711
/// Handles POST requests to `/api/v1/auth/sign-out`.
812
///
@@ -34,8 +38,8 @@ Future<Response> onRequest(RequestContext context) async {
3438
// Although authentication middleware should ensure a token is present,
3539
// this check acts as a safeguard.
3640
if (token == null || token.isEmpty) {
37-
print(
38-
'Error: Could not extract Bearer token for user ${user.id} in sign-out handler.',
41+
_logger.severe(
42+
'Could not extract Bearer token for user ${user.id} in sign-out handler.',
3943
);
4044
throw const OperationFailedException(
4145
'Internal error: Unable to retrieve authentication token for sign-out.',
@@ -55,9 +59,13 @@ Future<Response> onRequest(RequestContext context) async {
5559
} on HtHttpException catch (_) {
5660
// Let the central errorHandler middleware handle known exceptions
5761
rethrow;
58-
} catch (e) {
62+
} catch (e, s) {
5963
// Catch unexpected errors from the service layer
60-
print('Unexpected error in /sign-out handler for user ${user.id}: $e');
64+
_logger.severe(
65+
'Unexpected error in /sign-out handler for user ${user.id}',
66+
e,
67+
s,
68+
);
6169
// Let the central errorHandler handle this as a 500
6270
throw const OperationFailedException(
6371
'An unexpected error occurred during sign-out.',

0 commit comments

Comments
 (0)