Module: Kaui::ExceptionHelper

Included in:
SessionsController
Defined in:
app/helpers/kaui/exception_helper.rb

Instance Method Summary collapse

Instance Method Details

#standardize_exception(exception) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/helpers/kaui/exception_helper.rb', line 5

def standardize_exception(exception)
  if defined?(JRUBY_VERSION)
    case exception
    when ActiveRecord::JDBCError, ActiveRecord::NoDatabaseError, ActiveRecord::DatabaseConnectionError, ActiveRecord::ConnectionNotEstablished
      return I18n.translate('errors.messages.unable_to_connect_database')
    else
      return exception.message
    end
  end

  case exception
  when ActiveRecord::DatabaseConnectionError
    I18n.translate('errors.messages.unable_to_connect_database')
  when Errno::ECONNREFUSED, Errno::EBADF
    I18n.translate('errors.messages.unable_to_connect_killbill')
  when ->(e) { e.class.name.start_with?('KillBillClient::API') }
    I18n.translate('errors.messages.error_communicating_killbill')
  else
    nil
  end
end