Add non-breaking error category API
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() }
}
That seems ok to add to me but it's not super clear what is a fundamental error?
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
It looks like InvalidRsaKey for example is just us wrapping an error from 3rd parties so it's not super clear cut
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