How to rescue from a OAuth::Unauthorized exception in a Ruby on Rails application?

313 views
Skip to first unread message

J. Pablo Fernández

unread,
Feb 14, 2012, 3:00:48 AM2/14/12
to omni...@googlegroups.com

How can I rescue from an OAuth::Unauthorized exception as raised from OmniAuth in a Ruby on Rails application? I tried

  rescue_from OAuth::Unauthorized, :with => :unauthorized

but it didn't work, I presume because the exception is not coming from inside the rails app but from omniauth (somewhere earlier in the rack chain? or at least, outside the rails app).

Any ideas how can I make my app display a better error message than the generic "Something went wrong" that's shipped with Rails?

Michael Bleigh

unread,
Feb 21, 2012, 9:55:53 AM2/21/12
to omni...@googlegroups.com
Hmm...in what context are you getting the error? Depending on your answer the correct solution is either that the error in question should never happen in production or the omniauth-oauth library needs to handle the error.

J. Pablo Fernández

unread,
Mar 4, 2012, 5:00:42 AM3/4/12
to omni...@googlegroups.com
The context in which this error happens is that one of the admins types the wrong credentials for twitter or facebook and then someone tries to use twitter or facebook for logging in and they get that error.

Ivko Maksimovic

unread,
May 7, 2019, 8:31:17 AM5/7/19
to omniauth
In my case it happens when user cancels Twitter login
Reply all
Reply to author
Forward
0 new messages