Hi.

I'm just trying out Ruby on Rails, and I'm trying to create some application that takes a hostname from the user and then checks if it is connectible through Net::SSH and if it is, it should check if a file is present.

Quite simple, and I also almost reached goal. But I can't seem to implement what should happen if Net::SSH.start fails?

I just get a big Rails error page with param dumps and stuff, but actually I'd just like to do a render :text => 'Hey couldn't connect dewd' or something.

How is that doable? Do I have to make my own error page of some kind?
Thank you.

Hi.

I'm just trying out Ruby on Rails, and I'm trying to create some application that takes a hostname from the user and then checks if it is connectible through Net::SSH and if it is, it should check if a file is present.

Quite simple, and I also almost reached goal. But I can't seem to implement what should happen if Net::SSH.start fails?

I just get a big Rails error page with param dumps and stuff, but actually I'd just like to do a render :text => 'Hey couldn't connect dewd' or something.

How is that doable? Do I have to make my own error page of some kind?
Thank you.

Hope this would help:

around_filter :catch_exceptions

private
def catch_exceptions
yield
rescue => exception
logger.debug "Caught exception! #{exception}"
render :text => 'Hey couldn't connect'
raise
end

I'm able to do what I want to achieve with your code, but it also overrides all other errors, making it hard to debug - also seems to override my 'Insufficient admin priviliges' system.

Is there some way to tune the functionality so that it render :text if it is the Net::SSH related error, or yield if not?

Thank you :)

I'm able to do what I want to achieve with your code, but it also overrides all other errors, making it hard to debug - also seems to override my 'Insufficient admin priviliges' system.

Is there some way to tune the functionality so that it render :text if it is the Net::SSH related error, or yield if not?

Thank you :)

You can have this filter to only to a particular action

before_filter :catch_exceptions, :only => [:action_name]

Thank you, works like a charm.
Unfortunately the action SSH is called from, is giantic with lots of different functionality depending on post params, but I'll just make a new action dedicated for the SSH connection and then call that action from the original action.

Thanks again ;)

Thank you, works like a charm.
Unfortunately the action SSH is called from, is giantic with lots of different functionality depending on post params, but I'll just make a new action dedicated for the SSH connection and then call that action from the original action.

Thanks again ;)

That's great to hear :)

Actually it seems that the error is raised from my original action although moving it... Guess I'll have to live with that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.