refactor(headers): errors for parse_header
Header::parse_header() returns now a hyper Result instead of an option this will enable more precise Error messages in the future, currently most failures are reported as ::Error::Header. BREAKING CHANGE: parse_header returns Result instead of Option, related code did also change
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/error.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/error.rs
									
									
									
									
									
								
							| @@ -2,6 +2,7 @@ | ||||
| use std::error::Error as StdError; | ||||
| use std::fmt; | ||||
| use std::io::Error as IoError; | ||||
| use std::str::Utf8Error; | ||||
|  | ||||
| use httparse; | ||||
| use openssl::ssl::error::SslError; | ||||
| @@ -18,6 +19,7 @@ use self::Error::{ | ||||
|     Ssl, | ||||
|     TooLarge, | ||||
|     Http2, | ||||
|     Utf8 | ||||
| }; | ||||
|  | ||||
|  | ||||
| @@ -45,6 +47,8 @@ pub enum Error { | ||||
|     Ssl(SslError), | ||||
|     /// An HTTP/2-specific error, coming from the `solicit` library. | ||||
|     Http2(Http2Error), | ||||
|     /// Parsing a field as string failed | ||||
|     Utf8(Utf8Error), | ||||
|  | ||||
|     #[doc(hidden)] | ||||
|     __Nonexhaustive(Void) | ||||
| @@ -77,6 +81,7 @@ impl StdError for Error { | ||||
|             Io(ref e) => e.description(), | ||||
|             Ssl(ref e) => e.description(), | ||||
|             Http2(ref e) => e.description(), | ||||
|             Utf8(ref e) => e.description(), | ||||
|             Error::__Nonexhaustive(ref void) =>  match *void {} | ||||
|         } | ||||
|     } | ||||
| @@ -113,6 +118,12 @@ impl From<SslError> for Error { | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<Utf8Error> for Error { | ||||
|     fn from(err: Utf8Error) -> Error { | ||||
|         Utf8(err) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl From<httparse::Error> for Error { | ||||
|     fn from(err: httparse::Error) -> Error { | ||||
|         match err { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user