Skip to content

Commit 5f4ee57

Browse files
authored
fix: preserve TokenVerificationException error reasons in fetchAndConvertJwk (#100)
Fixed a bug where TokenVerificationException with JWK_FAILED_TO_LOAD was being incorrectly caught and re-wrapped as JWK_FAILED_TO_RESOLVE in the fetchAndConvertJwk method. Now TokenVerificationException is re-thrown as-is to preserve the original error reason. Also updated test to reflect current API version (2025-11-10).
1 parent 9f1b336 commit 5f4ee57

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/main/java/com/clerk/backend_api/helpers/security/token_verifiers/impl/JwtSessionTokenVerifier.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ private static String fetchAndConvertJwk(String kid, VerifyTokenOptions options)
235235
return keyToPem(key);
236236
}
237237
}
238+
} catch (TokenVerificationException e) {
239+
// Re-throw TokenVerificationException as-is to preserve the original error reason
240+
throw e;
238241
} catch (Exception e) {
239242
throw new TokenVerificationException(TokenVerificationErrorReason.JWK_FAILED_TO_RESOLVE, e);
240243
}

src/test/java/com/clerk/backend_api/hooks/ClerkBeforeRequestHookTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ void testBeforeRequestAddsHeader() throws Exception {
3434
HttpRequest modifiedRequest = hook.beforeRequest(context, originalRequest);
3535

3636
// Assert
37-
assertEquals("2024-10-01", modifiedRequest.headers().firstValue("Clerk-API-Version").orElse(null));
37+
assertEquals("2025-11-10", modifiedRequest.headers().firstValue("Clerk-API-Version").orElse(null));
3838
}
3939
}

0 commit comments

Comments
 (0)