Apr 26 2012

Little Ruby trick that made my night:

module ApiError
  HttpExceptions = [
    RestClient::Exception,
    SystemCallError,
    SocketError,
    EOFError,
    Timeout::Error,
  ]
end

With this in place, you can do:

begin
  RestClient.post("http://random/api")
rescue *ApiError::HttpExceptions => e
  logger.error(e)
end

Just never realized that rescue really just takes multiple args.

blog comments powered by Disqus