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

Add some helper functions for common usage #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

viraptor
Copy link

Helpers give one-line options for the typical use case: parse the parameters or 400, get required parameter or 400. No existing functionality is changed.

doctest are disabled in Cargo.toml to allow partial examples in the docs.

@untitaker
Copy link
Member

Hello @viraptor, I'd prefer if those helpers were methods on a trait that is impl'd for QueryMap.

/// ```
pub fn require_query_params(req: &mut Request) -> IronResult<QueryMap> {
req.get::<UrlEncodedQuery>()
.map_err(|err| IronError::new(err, status::BadRequest))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might be able to avoid these extra functions if we impl Into<IronError> for our own error types?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking I think it's wrong to do so - you want to specify an intelligent and semantic response when there is an error, not just toss 400 at everything.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of those helpers is IMO that I don't care about that.

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

Successfully merging this pull request may close these issues.

3 participants