Is there a way to determine if an Error
object thrown by the jwt.verify
function in the jsonwebtoken
library is of type TokenExpiredError
using Typescript's instanceof
? For example:
import jwt from "jsonwebtoken";
function someFunction() {
try {
return jwt.verify(token, key);
}catch(err) {
if(err instanceof TokenExpiredError) {
return attemptRenewal()
}
throw err
}
}
What is the correct way to import the TokenExpiredError
symbol?
I have looked for documentation on this class but could not find any. My initial approach was:
import { jwt, TokenExpiredError } from "jsonwebtoken";
However, this resulted in jwt
being undefined
.
While I am aware of workarounds like comparing string names of classes, I prefer cleaner code solutions.
My version of jsonwebtoken
is 8.5.1.