use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub struct JsonWebTokenBuildError {
message: String,
source: Box<dyn Error>,
}
impl JsonWebTokenBuildError {
pub fn new<E: Into<Box<dyn Error>>>(message: String, source: E) -> Self {
Self {
message,
source: source.into(),
}
}
}
impl fmt::Display for JsonWebTokenBuildError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(&self.message)
}
}
impl Error for JsonWebTokenBuildError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&*self.source)
}
}
#[derive(Debug)]
pub enum JsonWebTokenParseError {
InvalidToken(String),
InvalidSignature,
}
impl fmt::Display for JsonWebTokenParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
JsonWebTokenParseError::InvalidToken(msg) => f.write_str(msg),
JsonWebTokenParseError::InvalidSignature => f.write_str("The signature was invalid"),
}
}
}
impl Error for JsonWebTokenParseError {}