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>;
15
15
pub struct Error {
16
16
error : anyhow:: Error ,
17
17
status : crate :: StatusCode ,
18
+ type_name : Option < String > ,
18
19
}
19
20
20
21
impl Error {
@@ -23,10 +24,11 @@ impl Error {
23
24
/// The error type must be threadsafe and 'static, so that the Error will be
24
25
/// as well. If the error type does not provide a backtrace, a backtrace will
25
26
/// 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 {
27
28
Self {
28
29
status,
29
30
error : error. into ( ) ,
31
+ type_name : Some ( std:: any:: type_name :: < E > ( ) . to_string ( ) ) ,
30
32
}
31
33
}
32
34
@@ -38,6 +40,7 @@ impl Error {
38
40
Self {
39
41
status,
40
42
error : anyhow:: Error :: msg ( msg) ,
43
+ type_name : None ,
41
44
}
42
45
}
43
46
@@ -102,6 +105,11 @@ impl Error {
102
105
{
103
106
self . error . downcast_mut :: < E > ( )
104
107
}
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
+ }
105
113
}
106
114
107
115
impl Display for Error {
You can’t perform that action at this time.
0 commit comments