Just today I've found my fbgraph implementation has started returning a 400 Bad Request error which is causing an internal server error.
The controller looks like:
def fb
fbclient = FBGraph::Client.new(:client_id => 'ID', :secret_id => 'SECRET')
@fbname = fbclient.selection.user('129220333799040').feed.info!['data'][0].from.name
@fbmessage = fbclient.selection.user('129220333799040').feed.info!['data'][0].message
end
How can I check before calling @fbname in my view that I've received a 200 status?
Thanks.
Update: following Devin M's suggestion, I've switched the above action to
开发者_StackOverflowdef fb
fbclient = FBGraph::Client.new(:client_id => 'ID', :secret_id => 'SECRET')
begin
@fbname = fbclient.selection.user('129220333799040').feed.info!['data'][0].from.name
@fbmessage = fbclient.selection.user('129220333799040').feed.info!['data'][0].message
rescue
@fbname = "Facebook Account"
@fbmessage = "Facebook's API is a nightmare"
end
end
I think that you should write some tests for this, Its hard to work with Facebooks nightmare of an API. Although if you wanted to catch this error try using that way you can catch the specific error and take some action on it in the rescue portion.
begin
rescue
end
If you want me to take a look at the docs and see what you should catch let me know.
精彩评论