문제

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top