How to raise HTTP error in rails?

86 views
Skip to first unread message

Tsvetelina Borisova

unread,
Jul 25, 2012, 2:19:38 PM7/25/12
to rubyonra...@googlegroups.com
Hello, I have to handle this exception:   HTTP 502: Response body: Got EOF while waiting for outstanding responses (Koala::Facebook::APIError)

and I have written this test:
it "should handle Koala's error" do
        get :test_action
        response.should redirect_to root_url
        flash[:alert].should == "HTTP 502: Response body: Got EOF while waiting for outstanding responses (Koala::Facebook::APIError)"
    end

The file in which is used graph.batch is in lib folder and since I can't use things like redirect_to or something else in these files I decided to handle this error writing rescue block in ApplicationController:

     rescue_from Koala::Facebook::APIError do |exception|
        redirect_to root_url, :alert => exception.message
    end

But then I though that maybe I should handle 502 error and in that case I only have to write 502.html file in public folder. Right?
Can someone help me with the right path to handle this error. Thanks in advance :)

Frederick Cheung

unread,
Jul 28, 2012, 11:12:38 AM7/28/12
to rubyonra...@googlegroups.com


On Wednesday, July 25, 2012 7:19:38 PM UTC+1, Tsvetelina Borisova wrote:
The file in which is used graph.batch is in lib folder and since I can't use things like redirect_to or something else in these files I decided to handle this error writing rescue block in ApplicationController:

     rescue_from Koala::Facebook::APIError do |exception|
        redirect_to root_url, :alert => exception.message
    end

But then I though that maybe I should handle 502 error and in that case I only have to write 502.html file in public folder. Right?
Can someone help me with the right path to handle this error. Thanks in advance :)

It doesn't look like there is a 502 error for you to handle directly - Koala has wrapped that up inside a  Koala::Facebook::APIError. Rescuing at the controller with rescue_from sounds reasonable to me

Fred
Reply all
Reply to author
Forward
0 new messages