You can override the method http_auth_bodyin your custom reject application:
class CustomFailure < Devise::FailureApp
protected
def http_auth_body
return i18n_message unless request_format
method = "to_#{request_format}"
if method == "to_xml"
{ :errors => { :error => i18n_message } }.to_xml(:root => Rails.application.class.parent_name)
elsif {}.respond_to?(method)
{ :error => i18n_message }.send(method)
else
i18n_message
end
end
end
then add this to initializers/devise.rb:
config.warden do |manager|
manager.failure_app = CustomFailure
end
and add this to application.rb:
config.autoload_paths += %W(
result:
curl -X POST http://localhost:3000/users/sign_in.xml -d "{}"
<?xml version="1.0" encoding="UTF-8"?>
<DeviseCustom>
<errors>
<error>You need to sign in or sign up before continuing.</error>
</errors>
</DeviseCustom>
source
share