mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-09 00:00:12 +02:00
add IntoResponseFailed to existing fallible responses
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
async_trait,
|
async_trait,
|
||||||
extract::{rejection::BytesRejection, FromRequest, Request},
|
extract::{rejection::BytesRejection, FromRequest, Request},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, IntoResponseFailed, Response},
|
||||||
};
|
};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
@@ -124,7 +124,12 @@ where
|
|||||||
let mut buf = BytesMut::with_capacity(128);
|
let mut buf = BytesMut::with_capacity(128);
|
||||||
match &self.0.encode(&mut buf) {
|
match &self.0.encode(&mut buf) {
|
||||||
Ok(()) => buf.into_response(),
|
Ok(()) => buf.into_response(),
|
||||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
Err(err) => (
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
IntoResponseFailed,
|
||||||
|
err.to_string(),
|
||||||
|
)
|
||||||
|
.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use axum::{
|
use axum::{
|
||||||
http::{header, HeaderValue, StatusCode},
|
http::{header, HeaderValue, StatusCode},
|
||||||
response::{IntoResponse, Response},
|
response::{IntoResponse, IntoResponseFailed, Response},
|
||||||
};
|
};
|
||||||
use bytes::{BufMut, Bytes, BytesMut};
|
use bytes::{BufMut, Bytes, BytesMut};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -68,7 +68,12 @@ impl IntoResponse for ErasedJson {
|
|||||||
bytes,
|
bytes,
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response(),
|
||||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
Err(err) => (
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
IntoResponseFailed,
|
||||||
|
err.to_string(),
|
||||||
|
)
|
||||||
|
.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-2
@@ -1,7 +1,7 @@
|
|||||||
use crate::extract::Request;
|
use crate::extract::Request;
|
||||||
use crate::extract::{rejection::*, FromRequest, RawForm};
|
use crate::extract::{rejection::*, FromRequest, RawForm};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use axum_core::response::{IntoResponse, Response};
|
use axum_core::response::{IntoResponse, IntoResponseFailed, Response};
|
||||||
use axum_core::RequestExt;
|
use axum_core::RequestExt;
|
||||||
use http::header::CONTENT_TYPE;
|
use http::header::CONTENT_TYPE;
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
@@ -115,7 +115,12 @@ where
|
|||||||
body,
|
body,
|
||||||
)
|
)
|
||||||
.into_response(),
|
.into_response(),
|
||||||
Err(err) => (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()).into_response(),
|
Err(err) => (
|
||||||
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
IntoResponseFailed,
|
||||||
|
err.to_string(),
|
||||||
|
)
|
||||||
|
.into_response(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ pub use crate::Extension;
|
|||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use axum_core::response::{
|
pub use axum_core::response::{
|
||||||
AppendHeaders, ErrorResponse, IntoResponse, IntoResponseParts, Response, ResponseParts, Result,
|
AppendHeaders, ErrorResponse, IntoResponse, IntoResponseFailed, IntoResponseParts, Response,
|
||||||
|
ResponseParts, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
|
|||||||
Reference in New Issue
Block a user