1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-23 08:36:34 +00:00

Allow to access Error's backtrace object

This commit is contained in:
Nikolay Kim 2018-04-29 14:21:50 -07:00
parent 03ded62337
commit aa757a5be8
2 changed files with 19 additions and 0 deletions

View file

@ -6,6 +6,8 @@
* Add Content-Disposition to NamedFile #204 * Add Content-Disposition to NamedFile #204
* Allow to access Error's backtrace object
## 0.5.6 (2018-04-24) ## 0.5.6 (2018-04-24)

View file

@ -45,6 +45,16 @@ impl Error {
pub fn cause(&self) -> &ResponseError { pub fn cause(&self) -> &ResponseError {
self.cause.as_ref() self.cause.as_ref()
} }
/// Returns a reference to the Backtrace carried by this error, if it
/// carries one.
pub fn backtrace(&self) -> Option<&Backtrace> {
if let Some(bt) = self.cause.backtrace() {
Some(bt)
} else {
self.backtrace.as_ref()
}
}
} }
/// Error that can be converted to `HttpResponse` /// Error that can be converted to `HttpResponse`
@ -793,6 +803,13 @@ mod tests {
assert_eq!(format!("{}", e.cause().unwrap()), desc); assert_eq!(format!("{}", e.cause().unwrap()), desc);
} }
#[test]
fn test_backtrace() {
let orig = ErrorBadRequest("err");
let e: Error = orig.into();
assert!(e.backtrace().is_some());
}
#[test] #[test]
fn test_error_cause() { fn test_error_cause() {
let orig = io::Error::new(io::ErrorKind::Other, "other"); let orig = io::Error::new(io::ErrorKind::Other, "other");