This commit is contained in:
Philip Jenvey 2026-06-01 08:09:30 +08:00 committed by GitHub
commit c2b3ce4d70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -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()

View File

@ -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 {