Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion actix-web/src/error/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@ pub struct Error {
}

impl Error {
/// Returns the reference to the underlying `ResponseError`.
/// Returns a reference to the underlying `ResponseError`.
pub fn as_response_error(&self) -> &dyn ResponseError {
self.cause.as_ref()
}

/// Returns a mutable reference to the underlying `ResponseError`.
pub fn as_response_error_mut(&mut self) -> &mut dyn ResponseError {
self.cause.as_mut()
}

/// Similar to `as_response_error` but downcasts.
pub fn as_error<T: ResponseError + 'static>(&self) -> Option<&T> {
<dyn ResponseError>::downcast_ref(self.cause.as_ref())
}

/// Similar to `as_response_error_mut` but downcasts.
pub fn as_error_mut<T: ResponseError + 'static>(&mut self) -> Option<&mut T> {
<dyn ResponseError>::downcast_mut(self.cause.as_mut())
}

/// Shortcut for creating an `HttpResponse`.
pub fn error_response(&self) -> HttpResponse {
self.cause.error_response()
Expand Down
8 changes: 7 additions & 1 deletion actix-web/src/response/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,18 @@ impl<B> HttpResponse<B> {
self.res.head_mut()
}

/// The source `error` for this response
/// Returns a reference to the source `error` for this response.
#[inline]
pub fn error(&self) -> Option<&Error> {
self.error.as_ref()
}

/// Returns a mutable reference to the source `error` for this response.
#[inline]
pub fn error_mut(&mut self) -> Option<&mut Error> {
self.error.as_mut()
}

/// Get the response status code
#[inline]
pub fn status(&self) -> StatusCode {
Expand Down
Loading