Ruby-on-Rails: Developing a Custom Application Problem

I'm trying to configure Devise to return 401 to unauthorized API requests instead of redirecting, but I'm running into a boulder. Here's how I override this user failure behavior:

class CustomFailure < Devise::FailureApp
    include ActionController::Head
    include ActionController::MimeResponds

    def respond
        respond_to do |format|
            format.html {
                super
            }
            format.any { head :status => 401}
        end
    end
end

However, I get this error:

undefined local variable or method `lookup_context' for #<CustomFailure:0x000001031f6220>

and points to the line respond_to do |format|

What am I doing wrong?

+3
source share
1 answer
def respond
  unless request.format.to_sym == :html
    http_auth
  else
    super
  end
end

Devise :: FailureApp is an inherited form of ActionController :: Metal that interacts with Rack at a low level, so there is no answer to looking at related things

+7
source

Source: https://habr.com/ru/post/1777620/


All Articles