1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01: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
* Allow to access Error's backtrace object
## 0.5.6 (2018-04-24)

View File

@ -45,6 +45,16 @@ impl Error {
pub fn cause(&self) -> &ResponseError {
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`
@ -793,6 +803,13 @@ mod tests {
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]
fn test_error_cause() {
let orig = io::Error::new(io::ErrorKind::Other, "other");