mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
Allow to access Error's backtrace object
This commit is contained in:
parent
03ded62337
commit
aa757a5be8
@ -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)
|
||||||
|
|
||||||
|
17
src/error.rs
17
src/error.rs
@ -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");
|
||||||
|
Loading…
Reference in New Issue
Block a user