Closed robertohuertasm closed 5 years ago
Based solely on the error message, I'd say you need to map the error type to turn PayloadError
into actix_web::Error
. PayloadError
implements ResponseError
and actix_web::Error
implemented From<T: ResponseError>
so you should just be able to map the error type like:
fut.map_err(actix_web::Error::from)
Thanks @jesskfullwood! Your help was invaluable! Actually, just using from_err()
made the trick.
.wrap_fn(|mut req, srv| {
let fut = req
.take_payload()
.from_err() // don't forget this
.fold(BytesMut::new(), move |mut body, chunk| {
body.extend_from_slice(&chunk);
Ok::<_, PayloadError>(body)
})
.and_then(|bytes| {
let mut res = Response::Ok();
Ok(res.body(bytes))
});
fut.map(|r| req.into_response(r))
})
I even managed to make it work with a full middleware with just a slight modification. The return should be Box::new(fut.map(|r| req.into_response(r.into_body())))
instead.
I really, really appreciate your help! Thanks again!
Hi, I've been trying to migrate my old middleware to the latest version of
actix
but I'm getting errors all the time. Maybe some of you can help me with this š.This is my previous middleware:
I've used both the
extended
and theshort
(wrap_fn) way of creating new middlewares but I'm stuck trying to return a future from the payload.What am I doing wrong and certainly missing? I'd really appreciate your help. Thank you!