I have a Rails 4 application using Doorkeeper to require authentication in most controllers. When I go to one of those restricted routes, I see a blank page. I notice in my terminal, Puma says:
Filter chain halted as #Proc:0x007fd650803350@/.../doorkeeper-0.7.2/lib/doorkeeper/helpers/filter.rb:8 rendered or redirected Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)
How can I catch such 401 Unauthorized errors so I can display a custom page? My goal is to render a JSON response with a message about how to authenticate, instead of just showing a blank white page.
This is actually an issue on Doorkeeper. To have a custom JSON response for 401 Unauthorized errors instead of a blank page, in ApplicationController
I added:
def doorkeeper_unauthorized_render_options
{json: '{"status": "failure", "message":"401 Unauthorized"}'}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With