Skip to content

Commit 888e30a

Browse files
committed
feat: improve error handling
1 parent 406d6f1 commit 888e30a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/ByteSync.Functions/Helpers/Middlewares/JwtMiddleware.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,16 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next
4949
{
5050
var tokenHandler = new JwtSecurityTokenHandler();
5151

52+
bool isOK = false;
53+
Client? client = null;
5254
try
5355
{
5456
var claims = ValidateToken(tokenHandler, token);
5557

56-
var client = await GetClient(claims);
58+
client = await GetClient(claims);
5759
context.Items.Add(AuthConstants.FUNCTION_CONTEXT_CLIENT, client!);
58-
59-
await BeginScopeAndGoNext(context, next, client);
60+
61+
isOK = true;
6062
}
6163
catch (SecurityTokenExpiredException ex)
6264
{
@@ -73,6 +75,11 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next
7375
_logger.LogError(ex, "Error validating token");
7476
await HandleTokenError(context, "Invalid token");
7577
}
78+
79+
if (isOK)
80+
{
81+
await BeginScopeAndGoNext(context, next, client!);
82+
}
7683
}
7784
else
7885
{

0 commit comments

Comments
 (0)