plataformatec/devise — Issue #1443: endless redirect loop when overriding FailureApp
Author: JohnMerlino1
Created: 2011-11-14 18:39:58+00:00
State: open

Hey all, I created a custom failure app:

class CustomFailureApp < Devise::FailureApp
def respond
unless request.format.to_sym == :html
http_auth
else
store_location!
flash[:alert] = i18n_message
redirect_to redirect_url
end
end

def http_auth
super
self.status = 401
self.content_type = 'json'
self.response_body = {
:error => 'Could not authenticate you.',
:status => 401
}.to_json
end

If the response is html, then it should direct to sign in page. However, it does an endless redirect:

Started GET "/users/sign_in" for 127.0.0.1 at 2011-11-14 13:37:53 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed in 4ms

Started GET "/users/sign_in" for 127.0.0.1 at 2011-11-14 13:37:56 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed in 3ms

Started GET "/users/sign_in" for 127.0.0.1 at 2011-11-14 13:37:59 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed in 5ms

Started GET "/users/sign_in" for 127.0.0.1 at 2011-11-14 13:38:01 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed in 4ms

Started GET "/users/sign_in" for 127.0.0.1 at 2011-11-14 13:38:04 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"sign_in"}
Completed in 5ms

and it goes on and on and get message on browser "The page isn't redirecting properly".

It seems like there is some other redirect going on. But all I wangted to do is create a custom failure app and if html, then redirect user to home page, as usual.

thanks for response