warp
warp copied to clipboard
Param filter with user-defined rejection
updates filters::param2:
- changes name to
param_with_err. This still doesn't quite feel right to me, so let me know if there's other suggestions. - returns
Rejectiondirectly fromFromStrErr, instead converting theErrto aCauseand always returning anot foundRejection. - created a fuller example in the docstring.
Let me know if this is the idea you had from #255.
Playing around with this a bit, I'm not sure it makes sense to have users implement their own Err -> Rejection if Causes are going to be the main way of identifying errors in a recover. Also, from notes in the api, it looks like you're moving towards using custom rejections more generally.
So, perhaps it makes more sense to have param_with_err just return a custom rejection, instead of having the user define an extra impl that's not really that powerful.
I'm not sure it makes sense to have users implement their own Err -> Rejection if Causes are going to be the main way of identifying errors in a recover.
I'm not quite sure what you mean by this. However, relatedly, master has just seen a refactor of the rejection system which would affect this (#311).
Ok, I'll look at the new rejection system.
I've rebased on master. In this implementation, the user just has to implement reject::Reject for their error, then they can use it in param_with_err (formerly param2). Let me know if you have any questions on this now.
And it seems like you no longer need to implement std::error::Error to work with the custom rejection system, just reject::Reject.
It's been a while since this PR was submitted, I've updated it to better reflect the latest Rejection system.
Quick summary:
path::param will always return reject::not_found() if there's an error in parsing. path::param_with_reject will allow the user to specify a custom rejection in case of parsing failure.
I see that param2, which served this function previously (I think), was removed. Let me know if there's no longer interest and I can close this PR.
Hi, and sorry for the delay! So if I understand correctly what you are trying to achieve is being able to replace a Known rejection with a custom one right? If so can't you do that with a recover handler and find and return the response you want on that case