Skip to content

Commit c98d9cb

Browse files
committed
refactor(auth): Improve exception messages
- Use string interpolation - Use const constructors
1 parent bec62b0 commit c98d9cb

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/src/services/jwt_auth_token_service.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'dart:convert'; // For potential base64 decoding if needed
1+
// For potential base64 decoding if needed
22

33
import 'package:dart_jsonwebtoken/dart_jsonwebtoken.dart';
44
import 'package:ht_api/src/services/auth_token_service.dart';
@@ -103,7 +103,7 @@ class JwtAuthTokenService implements AuthTokenService {
103103
final jti = jwt.payload['jti'] as String?;
104104
if (jti == null || jti.isEmpty) {
105105
print(
106-
'[validateToken] Token validation failed: Missing or empty "jti" claim.');
106+
'[validateToken] Token validation failed: Missing or empty "jti" claim.',);
107107
// Throw specific exception for malformed token
108108
throw const BadRequestException(
109109
'Malformed token: Missing or empty JWT ID (jti) claim.',
@@ -114,7 +114,7 @@ class JwtAuthTokenService implements AuthTokenService {
114114
final isBlacklisted = await _blacklistService.isBlacklisted(jti);
115115
if (isBlacklisted) {
116116
print(
117-
'[validateToken] Token validation failed: Token is blacklisted (jti: $jti).');
117+
'[validateToken] Token validation failed: Token is blacklisted (jti: $jti).',);
118118
// Throw specific exception for blacklisted token
119119
throw const UnauthorizedException('Token has been invalidated.');
120120
}

lib/src/services/token_blacklist_service.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'dart:async';
22

3-
import 'package:meta/meta.dart';
43
import 'package:ht_shared/ht_shared.dart'; // Added for OperationFailedException
4+
import 'package:meta/meta.dart';
55

66
/// {@template token_blacklist_service}
77
/// Defines the interface for a service that manages a blacklist of
@@ -68,7 +68,7 @@ class InMemoryTokenBlacklistService implements TokenBlacklistService {
6868
);
6969
}
7070

71-
// Stores jti -> expiry DateTime
71+
/// Stores jti -> expiry DateTime
7272
@visibleForTesting
7373
final Map<String, DateTime> blacklistStore = {};
7474
Timer? _cleanupTimer;
@@ -95,7 +95,7 @@ class InMemoryTokenBlacklistService implements TokenBlacklistService {
9595
'[InMemoryTokenBlacklistService] Error adding jti $jti to store: $e',
9696
);
9797
throw OperationFailedException(
98-
'Failed to add token to blacklist: ${e.toString()}',
98+
'Failed to add token to blacklist: $e',
9999
);
100100
}
101101
}
@@ -128,7 +128,7 @@ class InMemoryTokenBlacklistService implements TokenBlacklistService {
128128
'[InMemoryTokenBlacklistService] Error checking blacklist for jti $jti: $e',
129129
);
130130
throw OperationFailedException(
131-
'Failed to check token blacklist: ${e.toString()}',
131+
'Failed to check token blacklist: $e',
132132
);
133133
}
134134
}

0 commit comments

Comments
 (0)