Skip to content

Commit 97ea137

Browse files
committed
fix(api): correct requestId handling in /auth/me endpoint
Removes the unnecessary and incorrect try-catch block around reading the `requestId` from the context in the `/api/v1/auth/me` handler. The `requestId` is guaranteed to be provided by the global middleware, so reading it directly resolves the `String?` to `String` type assignment error and aligns this handler's implementation with other authentication routes.
1 parent 39bc43f commit 97ea137

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

routes/api/v1/auth/me.dart

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,9 @@ Future<Response> onRequest(RequestContext context) async {
3030
throw const UnauthorizedException('Authentication required.');
3131
}
3232

33-
// Create metadata. Include requestId if it's available in context.
34-
// Note: Need to ensure RequestId is provided globally or adjust accordingly.
35-
String? requestId;
36-
try {
37-
// Attempt to read RequestId, handle gracefully if not provided at this level
38-
requestId = context.read<RequestId>().id;
39-
} catch (_) {
40-
// RequestId might not be provided directly in this context scope
41-
print('RequestId not found in context for /auth/me');
42-
}
43-
33+
// Create metadata, including the requestId from the context.
4434
final metadata = ResponseMetadata(
45-
requestId: requestId,
35+
requestId: context.read<RequestId>().id,
4636
timestamp: DateTime.now().toUtc(),
4737
);
4838

0 commit comments

Comments
 (0)