4
0

error.rs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_nativetls")]
  14. TlsError(native_tls::Error),
  15. /// There was a problem _establishing_ a TLS request.
  16. #[cfg(feature = "with_nativetls")]
  17. TlsHandshakeError(native_tls::HandshakeError<std::net::TcpStream>),
  18. /// Provided dns name is not valid
  19. #[cfg(feature = "with_rustls")]
  20. RustlsInvalidDnsNameError(webpki::InvalidDNSNameError),
  21. /// There was a problem decoding the response HTTP headers or body.
  22. #[cfg(feature = "with_https")]
  23. HttpError(httparse::Error),
  24. /// The HTTP response code was something other than 200 OK, along with the
  25. /// response code text, if present.
  26. #[cfg(feature = "with_https")]
  27. WrongHttpStatus(u16, Option<String>),
  28. }
  29. // From impls
  30. impl From<dns::WireError> for Error {
  31. fn from(inner: dns::WireError) -> Self {
  32. Self::WireError(inner)
  33. }
  34. }
  35. impl From<std::io::Error> for Error {
  36. fn from(inner: std::io::Error) -> Self {
  37. Self::NetworkError(inner)
  38. }
  39. }
  40. #[cfg(feature = "with_nativetls")]
  41. impl From<native_tls::Error> for Error {
  42. fn from(inner: native_tls::Error) -> Self {
  43. Self::TlsError(inner)
  44. }
  45. }
  46. #[cfg(feature = "with_nativetls")]
  47. impl From<native_tls::HandshakeError<std::net::TcpStream>> for Error {
  48. fn from(inner: native_tls::HandshakeError<std::net::TcpStream>) -> Self {
  49. Self::TlsHandshakeError(inner)
  50. }
  51. }
  52. #[cfg(feature = "with_rustls")]
  53. impl From<webpki::InvalidDNSNameError> for Error {
  54. fn from(inner: webpki::InvalidDNSNameError) -> Self {
  55. Self::RustlsInvalidDnsNameError(inner)
  56. }
  57. }
  58. #[cfg(feature = "with_https")]
  59. impl From<httparse::Error> for Error {
  60. fn from(inner: httparse::Error) -> Self {
  61. Self::HttpError(inner)
  62. }
  63. }