error: implement std's Error trait

This commit is contained in:
anna 2023-07-24 01:20:01 +02:00
parent c30e362d15
commit 1d2737122e
Signed by: fef
GPG key ID: 2585C2DC6D79B485
3 changed files with 23 additions and 0 deletions

View file

@ -52,6 +52,21 @@ impl ResponseError for Error {
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::BadToken(e) => Some(e),
Error::Crypto(e) => Some(e),
Error::Database(e) => Some(e),
Error::Invalid(e) => Some(e),
Error::Io(e) => Some(e),
Error::MalformedHeader(e) => Some(e),
Error::Reqwest(e) => Some(e),
_ => None,
}
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

View file

@ -360,6 +360,12 @@ where
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
self.0.source()
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -158,3 +158,5 @@ impl fmt::Display for Error {
Ok(())
}
}
impl std::error::Error for Error {}