feat(backend): Also export token-related errors#1980
Conversation
🦋 Changeset detectedLatest commit: 1cef899 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
tmilewski
left a comment
There was a problem hiding this comment.
@flawnn Thanks for your PR! Looks good to me! Would you mind adding a changeset?
807febb to
1825726
Compare
|
@tmilewski Done! |
nikosdouvlis
left a comment
There was a problem hiding this comment.
Hello @flawnn :)
This PR makes total sense to me, however, it also exposes a few internal errors that should probably remain internal for the time being.
Could you please share more details about your use case so we can better understand the changes we need to make?
|
Please also add a description to your PR. Thanks! |
Hey! The reason why I was suggesting this PR was that I wanted to be able to catch JWT Verification errors when working with try {
let v = await verifyJwt(authHeader.split(" ")[1], {} as VerifyJwtOptions);
next();
} catch (e) {
if (e instanceof TokenVerificationError) {
// Logic here doesn't make sense as there are multiple reasons obviously but just for sake of testing
return res.status(401).send("Token has expired");
}
return res.status(401).send("Invalid token");
}Maybe as a reason why I even decided doing that, is that the Clerk Middleware for Express actually just throws an error and doesn't pass that error on to following middlewares when decoding the JWT Token (in some cases). One case was, when the JWT Token expired. The problem with not passing it on to following middlewares is obviously that it doesn't allow for custom error handling. EDIT: https://clerk.com/docs/backend-requests/handling/nodejs#express-error-handlers The paragraph here basically isn't true. I am not able to handle all errors apparently. |
|
@flawnn, many thanks for the contribution and inciting an internal discussion about this! Thank you :) |
Description
Checklist
npm testruns as expected.npm run buildruns as expected.Type of change
Packages affected
@clerk/backend@clerk/chrome-extension@clerk/clerk-js@clerk/clerk-expo@clerk/fastifygatsby-plugin-clerk@clerk/localizations@clerk/nextjs@clerk/clerk-react@clerk/remix@clerk/clerk-sdk-node@clerk/shared@clerk/themes@clerk/typesbuild/tooling/chore