File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ pub type Result<T> = std::result::Result<T, Error>;
1515pub struct Error {
1616 error : anyhow:: Error ,
1717 status : crate :: StatusCode ,
18+ type_name : Option < String > ,
1819}
1920
2021impl Error {
@@ -23,10 +24,11 @@ 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 < E : Into < anyhow :: Error > > ( status : StatusCode , error : E ) -> Self {
2728 Self {
2829 status,
2930 error : error. into ( ) ,
31+ type_name : Some ( std:: any:: type_name :: < E > ( ) . to_string ( ) ) ,
3032 }
3133 }
3234
@@ -38,6 +40,7 @@ impl Error {
3840 Self {
3941 status,
4042 error : anyhow:: Error :: msg ( msg) ,
43+ type_name : None ,
4144 }
4245 }
4346
@@ -102,6 +105,11 @@ impl Error {
102105 {
103106 self . error . downcast_mut :: < E > ( )
104107 }
108+
109+ /// Retrieves a reference to the type name of the error, if available.
110+ pub fn type_name ( & self ) -> Option < & str > {
111+ self . type_name . as_deref ( )
112+ }
105113}
106114
107115impl Display for Error {
You can’t perform that action at this time.
0 commit comments