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 symbols for status codes #950

Merged
merged 1 commit into from
Mar 10, 2015

Conversation

dabrorius
Copy link
Contributor

This is a very simple implementation of feature requested in #934.

@dabrorius dabrorius force-pushed the allow_symbols_for_status_codes branch from 9b3bfb5 to 19a43fb Compare March 9, 2015 20:06
@dblock
Copy link
Member

dblock commented Mar 9, 2015

I like it. Rebase and squash please?

@dabrorius dabrorius force-pushed the allow_symbols_for_status_codes branch 2 times, most recently from a044ac8 to d23f5b6 Compare March 9, 2015 20:52
@dabrorius
Copy link
Contributor Author

Done

@@ -5,6 +5,7 @@

* [#936](https://github.com/intridea/grape/pull/936): Fixed default params processing for optional groups - [@dm1try](https://github.com/dm1try).
* [#942](https://github.com/intridea/grape/pull/942): Fixed forced presence for optional params when based on a reused entity that was also required in another context - [@croeck](https://github.com/croeck).
* [#950](https://github.com/intridea/grape/pull/950): Status method can now accept one of Rack::Utils status code symbols (:ok, :found, :bad_request, etc.) - [@dabrorius](https://github.com/dabrorius)
Copy link
Member

Choose a reason for hiding this comment

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

OCD: missing period after the line.

@dabrorius dabrorius force-pushed the allow_symbols_for_status_codes branch from d23f5b6 to e83cd2f Compare March 9, 2015 21:01
if Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status)
@status = Rack::Utils.status_code(status)
else
fail ArgumentError, "Status code :#{status} is not valid."
Copy link
Member

Choose a reason for hiding this comment

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

You want to specialize this error into Grape::Exceptions and make it localizable too, https://github.com/intridea/grape/blob/master/lib/grape/locale/en.yml.

I think not valid should be invalid, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an error that only developer should see, not the end user. Is there really need to localize it?
I used this as reference https://github.com/intridea/grape/blob/master/lib/grape/dsl/inside_route.rb#L28

@dabrorius dabrorius force-pushed the allow_symbols_for_status_codes branch 2 times, most recently from 3876c88 to 926a92f Compare March 9, 2015 22:25
@dabrorius
Copy link
Contributor Author

@dblock I changed the error message but didn't localize it yet. As I commented before, I'm not sure if it makes sense to allow user to translate a message that API end-users (as far as I understand) will never see. If it really needs to be localized I can change it but I wanted to make sure you really want that.

@dabrorius dabrorius force-pushed the allow_symbols_for_status_codes branch from 926a92f to 244671c Compare March 9, 2015 22:29
@dabrorius dabrorius closed this Mar 10, 2015
@dabrorius dabrorius reopened this Mar 10, 2015
@dblock
Copy link
Member

dblock commented Mar 10, 2015

Fair enough, merging.

dblock added a commit that referenced this pull request Mar 10, 2015
@dblock dblock merged commit 95331d6 into ruby-grape:master Mar 10, 2015
@swistaczek
Copy link

Good one @dabrorius 👍

@dabrorius
Copy link
Contributor Author

Thanks :)

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