jsonwebtoken icon indicating copy to clipboard operation
jsonwebtoken copied to clipboard

Add non-breaking error category API

Open srxg opened this issue 1 month ago • 4 comments

Answering the question: "was this failure a validation error or something else?" should be trivial for downstream consumers.

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum ErrorCategory { Fundamental, Validation, ThirdParty }

impl ErrorKind {
    pub fn category(&self) -> ErrorCategory {  todo!() }
    pub fn is_validation(&self) -> bool { matches!(self.category(), ErrorCategory::Validation) }
}

impl Error {
    pub fn category(&self) -> ErrorCategory { self.kind().category() }
}

srxg avatar Nov 12 '25 13:11 srxg

That seems ok to add to me but it's not super clear what is a fundamental error?

Keats avatar Nov 18 '25 07:11 Keats

The naming could be better for "fundamental error". I used that term to describe errors which indicate a 'fundamental' issue with the JWT or cryptographic key config e.g. InvalidKeyFormat, InvalidToken (for cases where the given token is not a valid jwt shape), RsaFailedSigning, InvalidRsaKey, etc

srxg avatar Nov 20 '25 07:11 srxg

It looks like InvalidRsaKey for example is just us wrapping an error from 3rd parties so it's not super clear cut

Keats avatar Nov 25 '25 10:11 Keats

Sure, but fact that it wraps a 3rd-party error doesn't change how callers should treat it, imo. It's still in the "non-validation" bucket

srxg avatar Nov 27 '25 19:11 srxg