@@ -4,6 +4,7 @@ use std::error::Error as StdError;
44use std:: fmt:: { self , Debug , Display } ;
55
66use crate :: StatusCode ;
7+ use std:: convert:: TryInto ;
78
89/// A specialized `Result` type for HTTP operations.
910///
@@ -23,24 +24,33 @@ impl Error {
2324 /// The error type must be threadsafe and 'static, so that the Error will be
2425 /// as well. If the error type does not provide a backtrace, a backtrace will
2526 /// be created here to ensure that a backtrace exists.
26- pub fn new ( status : StatusCode , error : impl Into < anyhow:: Error > ) -> Self {
27+ pub fn new < S > ( status : S , error : impl Into < anyhow:: Error > ) -> Self
28+ where
29+ S : TryInto < StatusCode > ,
30+ S :: Error : Debug ,
31+ {
2732 Self {
28- status,
33+ status : status
34+ . try_into ( )
35+ . expect ( "Could not convert into a valid `StatusCode`" ) ,
2936 error : error. into ( ) ,
3037 }
3138 }
3239
3340 /// Create a new error object from static string.
34- pub fn from_str < M > ( status : StatusCode , msg : M ) -> Self
41+ pub fn from_str < S , M > ( status : S , msg : M ) -> Self
3542 where
43+ S : TryInto < StatusCode > ,
44+ S :: Error : Debug ,
3645 M : Display + Debug + Send + Sync + ' static ,
3746 {
3847 Self {
39- status,
48+ status : status
49+ . try_into ( )
50+ . expect ( "Could not convert into a valid `StatusCode`" ) ,
4051 error : anyhow:: Error :: msg ( msg) ,
4152 }
4253 }
43-
4454 /// Create a new error from a message.
4555 pub ( crate ) fn new_adhoc < M > ( message : M ) -> Error
4656 where
0 commit comments