OmniAuth runs on Rack middleware, so rescue_from will not affect it, because it is an abstraction level higher than OmniAuth through the ActionController.
This error usually occurs due to the incorrect configuration of your OAuth settings. This basically means that your application is not authorized for authentication, not for user authentication.
A configuration error is something that you, as a developer, would like to mitigate, so I'm not sure why you would like to save such an exception.
If you absolutely must eliminate this exception, you can override and use the middleware that inherits from OmniAuth
module OmniAuth module Strategies class FacebookWithExceptionHandling < OmniAuth::Strategies::Facebook def call begin super raise OmniAuth::Unauthorized => e #handle appropriately in rack context here end end end end end Rails.application.config.middleware.use OmniAuth::Builder do provider OmniAuth::Strategies::FacebookWithExceptionHandling, api_key, #your api key secret_key, #your secret key end
source share