Implement HasKind for tor_dirclient::Error
This commit is contained in:
parent
7f9bbcb437
commit
49c87fa8f9
|
@ -3028,6 +3028,7 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tor-circmgr",
|
"tor-circmgr",
|
||||||
|
"tor-error",
|
||||||
"tor-llcrypto",
|
"tor-llcrypto",
|
||||||
"tor-netdoc",
|
"tor-netdoc",
|
||||||
"tor-proto",
|
"tor-proto",
|
||||||
|
|
|
@ -19,6 +19,7 @@ routerdesc = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
tor-circmgr = { path="../tor-circmgr", version = "0.0.4"}
|
tor-circmgr = { path="../tor-circmgr", version = "0.0.4"}
|
||||||
|
tor-error = { path="../tor-error", version = "0.0.1"}
|
||||||
tor-llcrypto = { path="../tor-llcrypto", version = "0.0.3"}
|
tor-llcrypto = { path="../tor-llcrypto", version = "0.0.3"}
|
||||||
tor-proto = { path="../tor-proto", version = "0.0.4"}
|
tor-proto = { path="../tor-proto", version = "0.0.4"}
|
||||||
tor-netdoc = { path="../tor-netdoc", version = "0.0.4"}
|
tor-netdoc = { path="../tor-netdoc", version = "0.0.4"}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use tor_error::{ErrorKind, HasKind};
|
||||||
use tor_rtcompat::TimeoutError;
|
use tor_rtcompat::TimeoutError;
|
||||||
|
|
||||||
/// An error originating from the tor-dirclient crate.
|
/// An error originating from the tor-dirclient crate.
|
||||||
|
@ -81,3 +82,26 @@ impl Error {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl HasKind for Error {
|
||||||
|
fn kind(&self) -> ErrorKind {
|
||||||
|
use Error as E;
|
||||||
|
use ErrorKind as EK;
|
||||||
|
match self {
|
||||||
|
E::DirTimeout => EK::ExitTimeout,
|
||||||
|
E::TruncatedHeaders => EK::TorProtocolViolation,
|
||||||
|
E::HttpStatus(_) => EK::RemoteRefused,
|
||||||
|
E::ResponseTooLong(_) => EK::TorProtocolViolation,
|
||||||
|
E::Utf8Encoding(_) => EK::TorProtocolViolation,
|
||||||
|
// TODO: it would be good to get more information out of the IoError
|
||||||
|
// in this case, but that would require a bunch of gnarly
|
||||||
|
// downcasting.
|
||||||
|
E::IoError(_) => EK::RemoteStreamError,
|
||||||
|
E::Proto(e) => e.kind(),
|
||||||
|
E::CircMgr(e) => e.kind(),
|
||||||
|
E::HttparseError(_) => EK::TorProtocolViolation,
|
||||||
|
E::HttpError(_) => EK::Internal,
|
||||||
|
E::ContentEncoding(_) => EK::TorProtocolViolation,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue