grape: error!('Unauthorized', 401) does not work as expected

I’m using grape in a rails app (4.0.4).

It is the only code with which I have an issue: the others are working just fine.

Basically when I try to access to the ping action below, it does a redirect 302 to the home api and in my tests the status code is 302 instead of 401…It seems really strange to me, but is it supposed to be that way?

      desc "Returns pong if logged in correctly."
      params do
        requires :token, type: String, desc: "Access token."
      end
      get :ping do
        error!('Unauthorized', 401)
      end

Thanks in advance for your replies!

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

Maybe some “magic” middleware handles 401 response? Could you provide a stacktrace for your SessionsController#new ?

 def new
  p caller # this one
  ...
 end