4
0

error.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /// Something that can go wrong making a DNS request.
  2. #[derive(Debug)]
  3. pub enum Error {
  4. /// The data in the response did not parse correctly from the DNS wire
  5. /// protocol format.
  6. WireError(dns::WireError),
  7. /// There was a problem with the network making a TCP or UDP request.
  8. NetworkError(std::io::Error),
  9. /// Not enough information was received from the server before a `read`
  10. /// call returned zero bytes.
  11. TruncatedResponse,
  12. /// There was a problem making a TLS request.
  13. #[cfg(feature = "with_tls")]
  14. TlsError(native_tls::Error),
  15. /// There was a problem _establishing_ a TLS request.
  16. #[cfg(feature = "with_tls")]
  17. TlsHandshakeError(native_tls::HandshakeError<std::net::TcpStream>),
  18. /// There was a problem decoding the response HTTP headers or body.
  19. #[cfg(feature = "with_https")]
  20. HttpError(httparse::Error),
  21. /// The HTTP response code was something other than 200 OK, along with the
  22. /// response code text, if present.
  23. #[cfg(feature = "with_https")]
  24. WrongHttpStatus(u16, Option<String>),
  25. }
  26. // From impls
  27. impl From<dns::WireError> for Error {
  28. fn from(inner: dns::WireError) -> Self {
  29. Self::WireError(inner)
  30. }
  31. }
  32. impl From<std::io::Error> for Error {
  33. fn from(inner: std::io::Error) -> Self {
  34. Self::NetworkError(inner)
  35. }
  36. }
  37. #[cfg(feature = "with_tls")]
  38. impl From<native_tls::Error> for Error {
  39. fn from(inner: native_tls::Error) -> Self {
  40. Self::TlsError(inner)
  41. }
  42. }
  43. #[cfg(feature = "with_tls")]
  44. impl From<native_tls::HandshakeError<std::net::TcpStream>> for Error {
  45. fn from(inner: native_tls::HandshakeError<std::net::TcpStream>) -> Self {
  46. Self::TlsHandshakeError(inner)
  47. }
  48. }
  49. #[cfg(feature = "with_https")]
  50. impl From<httparse::Error> for Error {
  51. fn from(inner: httparse::Error) -> Self {
  52. Self::HttpError(inner)
  53. }
  54. }