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

allow params post-processing #74

Closed
iliakan opened this issue Aug 24, 2014 · 1 comment
Closed

allow params post-processing #74

iliakan opened this issue Aug 24, 2014 · 1 comment

Comments

@iliakan
Copy link
Contributor

iliakan commented Aug 24, 2014

Express had a way to post-process app.params.

For example, a param with name :id could be cast to ObjectId (and if fails, throw 404), or :userId becomes the autoloaded user.

In the particular case of using Mongo/Mongoose that was quite helpful, because if a param does not validate as ObjectId, then findById(id) and findOne(_id: id) methods throw CastError.

To handle the error, we need to either to validate it manually (in try..catch) in every route which uses user-provided id, or just rely on a global agreement (implemented by post-processing params) ":id or :...Id" are ObjectIds" could be helpful.

P.S. This functionality seems to exist for koa-route: https://github.com/segmentio/koa-params
Why not to implement it here, it fits nicely.

@alexmingoia
Copy link
Collaborator

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

2 participants