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

Error middleware support using rack util's symbols as status #2274

Merged
merged 2 commits into from
Jul 31, 2022
Merged

Error middleware support using rack util's symbols as status #2274

merged 2 commits into from
Jul 31, 2022

Conversation

dhruvCW
Copy link
Contributor

@dhruvCW dhruvCW commented Jul 30, 2022

support the ability to use the Rack::Utils's status_code symbols instead of integers.

support the ability to use the Rack::Utils's status_code symbols instead of integers.
@dblock
Copy link
Member

dblock commented Jul 30, 2022

I don't see why not. Update CHANGELOG and we can merge.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Looking at this more carefully, I saw that we were documenting that you could set status with a code in https://github.com/ruby-grape/grape#http-status-code, and we have specs that show you can do this here.

      it 'can be set with a status code symbol' do
        subject.get '/foo' do
          status :see_other
        end
        get '/foo'
        expect(last_response.status).to eq 303
      end

So why do we need this? Or at least should we be removing the call in https://github.com/ruby-grape/grape/blob/master/lib/grape/dsl/inside_route.rb#L196?

@dhruvCW
Copy link
Contributor Author

dhruvCW commented Jul 31, 2022

So why do we need this?

The reason is so the status code can be a symbol when using the error middleware to generate an error like so error!(response, :forbidden)

IMO the two use cases don't really converge.

@dblock dblock merged commit 362724d into ruby-grape:master Jul 31, 2022
@dblock
Copy link
Member

dblock commented Jul 31, 2022

Ok, my only concern was if we call Rack::Utils.status_code twice all the time, but it doesn't look like it. Merged.

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.

2 participants