why is the exception necessary? re: raise_error_if_necessary

43 views
Skip to first unread message

mikeymicrophone

unread,
Sep 15, 2011, 4:37:33 PM9/15/11
to facebooker
I am getting a Mogli::Client::HTTPException when I call
current_facebook_user.fetch.

It seems to happen when I am actually logged out of Facebook - yet for
some reason current_facebook_user does not return nil.

After I've logged out of Facebook, the log in button often doesn't
show until I refresh twice - anyone familiar with this issue?

Oldřich Vetešník

unread,
Sep 16, 2011, 4:02:04 AM9/16/11
to facebooker
Not with this particular issue, but we ran into something similar when
someone's access token has expired. The problem was, that the HTTParty
response code was 400 but it contained an OAuthException which never
got properly raised (HTTPException got raised instead).

# Log
------------- Mogli::Client::HTTPException -------------
Wed Aug 31 14:49:26 +0200 2011
data.code: 400
#<HTTParty::Response:0xa03a570
@parsed_response={"error"=>{"type"=>"OAuthException",
"message"=>"Error validating access
token: Session has expired at unix time 1314788400. The current unix
time is 1314794966."}}, @response=#
<Net::HTTPBadRequest 400 Bad Request readbody=true>,
@headers={"expires"=>["Sat, 01 Jan 2000 00:00:00 GMT"], "p3p"=>
["CP=\"Facebook does not have a P3P policy. Learn why here: http://fb.me/p3p\""],
"content-type"=>["text/javascript;
charset=UTF-8"], "connection"=>["close"], "www-authenticate"=>["OAuth
\"Facebook Platform\" \"invalid_token\" \"Error
validating access token: Session has expired at unix time 1314788400.
The current unix time is 1314794966.\""], "date"=>
["Wed, 31 Aug 2011 12:49:26 GMT"], "content-length"=>["160"], "set-
cookie"=>["datr=1i1eTijMMNsbHmmxZi-oicp1; expires=Fri,
30-Aug-2013 12:49:26 GMT; path=/; domain=.facebook.com; httponly"],
"cache-control"=>["no-store"], "x-fb-rev"=>["432627"],
"x-fb-server"=>["10.62.216.37"], "pragma"=>["no-cache"]}>
--------------------------------------------------------

# https://github.com/mmangino/mogli/blob/master/lib/mogli/client.rb
def raise_error_if_necessary(data)
raise HTTPException if data.respond_to?(:code) and data.code != 200
if data.kind_of?(Hash)
if data.keys.size == 1 and data["error"]
self.class.raise_error_by_type_and_message(data["error"]
["type"], data["error"]["message"])
end
end
end

So we modified the code a bit to get the response logged so we know
which one it is.

# https://github.com/mmangino/mogli/blob/master/lib/mogli/client.rb
(modified)
def raise_error_if_necessary(data)
if data.respond_to?(:code) and data.code != 200
# DEBUG
@logger ||= Logger.new('./log/production.log')
@logger.error '------------- Mogli::Client::HTTPException
-------------'
@logger.error Time.now
@logger.error "data.code: #{ data.code }" if data.respond_to?
(:code)
@logger.error data.inspect
@logger.error
'--------------------------------------------------------'
raise HTTPException
end
if data.kind_of?(Hash)
if data.keys.size == 1 and data["error"]
self.class.raise_error_by_type_and_message(data["error"]
["type"], data["error"]["message"])
end
end
end

Don't know if it helps, but it's worth a try.

Ollie

sasi

unread,
Sep 19, 2011, 10:47:24 AM9/19/11
to facebooker
Hi Mikey,

I am also getting Error like you.

Did you get any solution for this?

Regards
sasi

googler

unread,
Nov 3, 2011, 5:44:52 AM11/3/11
to facebooker
I'm having the same issue. Any solution found yet?

Thanks
Pascal

Mike Mangino

unread,
Nov 3, 2011, 9:29:56 AM11/3/11
to faceb...@googlegroups.com
I'm not sure there is a solution. It takes several requests for Facebook to sort out the cookie situation. It's a side effect of the way they do login and logout.

Mike

> --
> You received this message because you are subscribed to the Google Groups "facebooker" group.
> To post to this group, send email to faceb...@googlegroups.com.
> To unsubscribe from this group, send email to facebooker+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/facebooker?hl=en.
>

Reply all
Reply to author
Forward
0 new messages