Revamp error handling model (#402)

* Revamp error handling model

* changelog improvements and typo fixes

* Fix a few more Infallible bounds

* minor docs fixes
This commit is contained in:
David Pedersen
2021-10-24 17:33:03 +00:00
committed by GitHub
parent 1a78a3f224
commit f10508db0b
19 changed files with 501 additions and 558 deletions
+7 -6
View File
@@ -6,6 +6,7 @@ use futures_util::ready;
use http::{Request, Response};
use pin_project_lite::pin_project;
use std::{
convert::Infallible,
future::Future,
pin::Pin,
task::{Context, Poll},
@@ -33,8 +34,8 @@ fn traits() {
impl<A, B, ReqBody> Service<Request<ReqBody>> for Or<A, B>
where
A: Service<Request<ReqBody>, Response = Response<BoxBody>> + Clone,
B: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = A::Error> + Clone,
A: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = Infallible> + Clone,
B: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = Infallible> + Clone,
ReqBody: Send + Sync + 'static,
A: Send + 'static,
B: Send + 'static,
@@ -42,7 +43,7 @@ where
B::Future: Send + 'static,
{
type Response = Response<BoxBody>;
type Error = A::Error;
type Error = Infallible;
type Future = ResponseFuture<A, B, ReqBody>;
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
@@ -89,11 +90,11 @@ pin_project! {
impl<A, B, ReqBody> Future for ResponseFuture<A, B, ReqBody>
where
A: Service<Request<ReqBody>, Response = Response<BoxBody>>,
B: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = A::Error>,
A: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = Infallible>,
B: Service<Request<ReqBody>, Response = Response<BoxBody>, Error = Infallible>,
ReqBody: Send + Sync + 'static,
{
type Output = Result<Response<BoxBody>, A::Error>;
type Output = Result<Response<BoxBody>, Infallible>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
loop {