Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby-on-Rails: Devise custom failure app problem

I am trying to set up Devise to return 401 to unauthorized API requests instead of redirects but I'm running into a boulder. This is how I am overriding it's custom 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 am getting this error:

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

and it points to the respond_to do |format| line

What am I doing wrong?

like image 872
David Avatar asked Feb 26 '26 17:02

David


1 Answers

def respond
  unless request.format.to_sym == :html
    http_auth
  else
    super
  end
end

Devise::FailureApp is inherited form ActionController::Metal which is interacting with Rack on low level, so there is no respond_to view related stuff

like image 89
Sigurd Avatar answered Feb 28 '26 10:02

Sigurd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!