Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom error for path param #255

Closed
hwchen opened this issue Jul 19, 2019 · 4 comments
Closed

custom error for path param #255

hwchen opened this issue Jul 19, 2019 · 4 comments

Comments

@hwchen
Copy link
Contributor

hwchen commented Jul 19, 2019

Hello,

When parsing the param where I have a custom type, e.g. path!(api / MyParam), it seems like any error in parsing will result in Rejection(NotFound). Is it possible for the parsing error to be passed down so that I can deal with it in .recover()?

Thanks!

@seanmonstar
Copy link
Owner

There exists warp::path::param2 currently, but I think it needs some tweaks. But instead of boring you with those without asking, you could try warp::path(api).and(warp::path::param2::<MyParam>()). The error will be in the Rejection::cause().

@hwchen
Copy link
Contributor Author

hwchen commented Jul 19, 2019

Awesome, worked perfectly.

I'm curious what you think the tweaks need to be.

@seanmonstar
Copy link
Owner

  • A better name, since I don't expect it to replace param.
  • It probably shouldn't return a NOT_FOUND rejection with the error as a cause, but just the custom error as the direct rejection.

@hwchen
Copy link
Contributor Author

hwchen commented Jul 30, 2019

I’ve also had a hard time coming up with a good name :) . I guess it should somehow convey param_with_explicit_err, but shorter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants