Skip to content

Commit

Permalink
update for new rejection system
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchen committed Nov 15, 2019
1 parent b521d21 commit 1891d5f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/filters/path.rs
Expand Up @@ -246,10 +246,13 @@ pub fn param<T: FromStr + Send + 'static>() -> impl Filter<Extract = One<T>, Err
///
/// If the value could not be parsed, rejects with a custom [`Rejection`][].
///
/// You'll need to implement [`reject::Reject`][] as a marker trait.
///
/// Since [`warp::reject::custom`][] is used to create a `Rejection` under the hood,
/// a [`recover`][] filter should convert this `Rejection` into a `Reply`, or else
/// this will be returned as a `500 Internal Server Error`.
///
/// [`reject::Reject`]: ../../reject/trait.Reject.html
/// [`Rejection`]: ../../reject/struct.Rejection.html
/// [`recover`]: ../trait.Filter.html#method.recover
/// [`warp::reject::custom`]: ../../reject/fn.custom.html
Expand All @@ -266,8 +269,11 @@ pub fn param<T: FromStr + Send + 'static>() -> impl Filter<Extract = One<T>, Err
/// status,
/// Response,
/// },
/// reject::{
/// Reject,
/// Rejection,
/// },
/// Filter,
/// Rejection
/// };
///
/// #[derive(Debug)]
Expand Down Expand Up @@ -295,14 +301,15 @@ pub fn param<T: FromStr + Send + 'static>() -> impl Filter<Extract = One<T>, Err
/// }
///
/// impl std::error::Error for MyError {};
/// impl Reject for MyError {};
///
/// let route = warp::path::param_with_err()
/// .map(|id: MyStruct| {
/// format!("You asked for /{:?}", id)
/// })
/// .recover(|err: Rejection| {
/// let err = {
/// if let Some(e) = err.find_cause::<MyError>() {
/// if let Some(e) = err.find::<MyError>() {
/// Ok(Response::builder()
/// .status(status::StatusCode::from_u16(404).unwrap())
/// .body(e.to_string())
Expand All @@ -318,7 +325,7 @@ pub fn param<T: FromStr + Send + 'static>() -> impl Filter<Extract = One<T>, Err
pub fn param_with_err<T>() -> impl Filter<Extract = One<T>, Error = Rejection> + Copy
where
T: FromStr + Send + 'static,
T::Err: Into<reject::Cause>,
T::Err: reject::Reject,
{
segment(|seg| {
log::trace!("param?: {:?}", seg);
Expand All @@ -327,7 +334,7 @@ where
}
T::from_str(seg).map(one).map_err(|err| {
#[allow(deprecated)]
reject::custom(err.into())
reject::custom(err)
})
})
}
Expand Down

0 comments on commit 1891d5f

Please sign in to comment.