When using Ktor Server authentication plugin with ...
# ktor
a
When using Ktor Server authentication plugin with JWT, and use it to protect routes, when the token expire it will throw this exception:
Copy code
com.auth0.jwt.exceptions.TokenExpiredException: The Token has expired on 2024-03-28T12:11:25Z.
	at com.auth0.jwt.JWTVerifier$BaseVerification.assertValidInstantClaim(JWTVerifier.java:346)
	at com.auth0.jwt.JWTVerifier$BaseVerification.lambda$addMandatoryClaimChecks$17(JWTVerifier.java:308)
	at com.auth0.jwt.JWTVerifier$BaseVerification$1.verify(JWTVerifier.java:405)
	at com.auth0.jwt.JWTVerifier.verifyClaims(JWTVerifier.java:482)
	at com.auth0.jwt.JWTVerifier.verify(JWTVerifier.java:464)
	at com.auth0.jwt.JWTVerifier.verify(JWTVerifier.java:445)
	at io.ktor.server.auth.jwt.JWTUtilsKt.verifyAndValidate(JWTUtils.kt:95)
Is there a way to not print this exception to the log? I tried using StatusPages Plugin to handle the exception but it didn't work (Maybe this is just a message that is being printed) + even if it works it will not when using WebSockets because StatusPages plugin doesn't support Web Sockets
a
So the only problem is that the stack trace pollutes the log?
a
Yes
a
I think you can solve the problem by configuring the logger to exclude the
TokenExpiredException
from the logs.
a
Any idea how?
a
What logger provider do you use?
a
The ktor server default logger (logback classic)
a
You can find an answer here.
👍 1