1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-31 00:50:20 +02:00

refined error model (#2253)

This commit is contained in:
Rob Ede
2021-06-17 17:57:58 +01:00
committed by GitHub
parent bb0331ae28
commit 532f7b9923
69 changed files with 1498 additions and 901 deletions

View File

@@ -8,7 +8,7 @@ use std::{
};
use actix_http::{
body::{Body, MessageBody},
body::{AnyBody, Body, MessageBody},
http::{header::HeaderMap, StatusCode},
Extensions, Response, ResponseHead,
};
@@ -25,12 +25,12 @@ use {
use crate::{error::Error, HttpResponseBuilder};
/// An HTTP Response
pub struct HttpResponse<B = Body> {
pub struct HttpResponse<B = AnyBody> {
res: Response<B>,
pub(crate) error: Option<Error>,
}
impl HttpResponse<Body> {
impl HttpResponse<AnyBody> {
/// Create HTTP response builder with specific status.
#[inline]
pub fn build(status: StatusCode) -> HttpResponseBuilder {
@@ -48,13 +48,8 @@ impl HttpResponse<Body> {
/// Create an error response.
#[inline]
pub fn from_error(error: Error) -> Self {
let res = error.as_response_error().error_response();
Self {
res,
error: Some(error),
}
pub fn from_error(error: impl Into<Error>) -> Self {
error.into().as_response_error().error_response()
}
}
@@ -238,7 +233,6 @@ impl<B> HttpResponse<B> {
impl<B> fmt::Debug for HttpResponse<B>
where
B: MessageBody,
B::Error: Into<Error>,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("HttpResponse")