Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch Koala::Facebook::APIError OAuthException or user password reset

i was wondering how i can catch a koala oauth exception (for example user password reset).

right now this is what i have / use so far:

rescue_from Koala::Facebook::APIError do
  # redirect to fb auth dialog
end

but this catches all errors.. how i can do that with just oauth or only password reset?

EDIT:

found out a more explicit solution to the problem:

rescue_from Koala::Facebook::APIError do |exception|
  if exception.fb_error_type == 190
    # password reset - redirect to auth dialog
  else
    raise "Facebook Error: #{exception.fb_error_type}"
  end
end

thanks in advance oliver

like image 850
Oliver Avatar asked Sep 01 '11 13:09

Oliver


1 Answers

I will show you some code I have, and how I manage to catch and rescue from Koala exceptions:

def post_message_facebook_wall(message)
    unless self.token.nil?
      begin
        facebook_graph = Koala::Facebook::GraphAPI.new(self.token)
        object_from_koala = facebook_graph.put_wall_post(message)
      rescue Koala::Facebook::APIError => exc
        logger.error("Problems posting to Facebook Wall..."+self.inspect+" "+exc.message)
      end
    end
end

This rescue Koala::Facebook::APIError => exc should do the trick.

like image 145
Nobita Avatar answered Oct 06 '22 00:10

Nobita