401 Custom Page in Rails with Doorkeeper

I have a Rails 4 application using Doorkeeper to authenticate with most controllers. When I go to one of these limited routes, I see a blank page. I noticed in my terminal that Puma says:

Filter chain stopped as #Proc: 0x007fd650803350 @ / ... / doorkeeper-0.7.2 / lib / doorkeeper / helpers / filter.rb: 8 displayed or redirected Completed 401 Unauthorized in 1 ms (ActiveRecord: 0.0ms)

How can I catch such 401 unauthorized errors so that I can display a custom page? My goal is to display a JSON response with an authentication message, and not just show a blank white page.

+4
source share
1 answer

This is actually a problem on Doorkeeper . To have a custom JSON response for 401 unauthorized errors instead of a blank page, ApplicationControllerI added:

def doorkeeper_unauthorized_render_options
  {json: '{"status": "failure", "message":"401 Unauthorized"}'}
end
+7
source

All Articles