Closed rightaway closed 5 years ago
What do you think about this feature request? Because currently the code is messy
let verified
try {
verified = jws.verify(signature, algorithm, secretOrKey)
} catch (e) {
if (e.name === 'TypeError [ERR_INVALID_ARG_TYPE]') {
log(e)
} else {
throw e // something unexpected
}
}
if (!verified) {
log(e)
} else {
// verified
}
If the feature request is approved then the code can just become
if (!jws.verify(signature, algorithm, secretOrKey)) {
log(e)
} else {
// verified
}
Is there any agreement on this issue or there's no interest in such a change by the maintainers?
While the specific error raised could likely be improved - I do believe passing something you expected to be a JWS that turned out not to be is quite exceptional, and hiding that information is not desirable in the general sense.
There are other reasons the verify
call will throw as well, so I don't think your code will end up changing in any significant sense.
Appreciate the feedback nonetheless.
Thanks
What are the other reasons that will cause verify
to throw?
If you pass a random string like 'test' to jws.verify, you get this error. Instead it should just return false.