Как избежать OCIError в приложении rails? - PullRequest
0 голосов
/ 20 мая 2010
OCIError (ORA-12541: TNS:no listener):
    oci8.c:270:in oci8lib.so
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:223:in `new'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:223:in `new_connection'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:328:in `initialize'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `new'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb:24:in `initialize'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in `new'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_connection.rb:9:in `create'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-oracle_enhanced-adapter-1.2.4/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb:50:in `oracle_enhanced_connection'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:291:in `send'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:291:in `connection='
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:259:in `retrieve_connection'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_adapters/abstract/connection_specification.rb:78:in `connection'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1063:in `table_exists?'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:1153:in `inspect'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/class/inheritable_attributes.rb:131:in `to_proc'
    /usr/local/ruby-1.8.7-p248/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:426:in `collect'

Похоже, что приложение rails потеряло соединение с Oracle, как избежать этого в контроллере приложения:

  def rescue_action_in_public(exception)

Я использую

def rescue_action_in_public(exception)
case exception.class.to_s
when "OCIError"
  # my solution
end

Это все еще бросает меня 500.html

1 Ответ

0 голосов
/ 20 мая 2010

Если OCIError находится внутри модуля, он не будет совпадать, потому что exception.class может возвращать что-то вроде Some :: Module :: OCIError.

Вы можете сравнить класс напрямую:

case exception
  when OCIError
    # my solution
  end
end

или, если вы хотите использовать имя класса (не рекомендуется):

case exception.class.to_s
  when /OCIError/
    # my solution
  end
end
...