Module: Eurydice::Pelops::ExceptionHelpers

Included in:
ColumnFamily, Keyspace, Mutator
Defined in:
lib/eurydice/pelops.rb

Instance Method Summary collapse

Instance Method Details

#thrift_exception_handlerObject



115
116
117
118
119
# File 'lib/eurydice/pelops.rb', line 115

def thrift_exception_handler
  yield
rescue Exception => e
  transform_thrift_exception(e)
end

#transform_thrift_exception(e) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/eurydice/pelops.rb', line 90

def transform_thrift_exception(e)
  if e.respond_to?(:cause)
    case e.cause
    when Cassandra::InvalidRequestException, ::Pelops::InvalidRequestException
      message = e.cause.why
      backtrace = e.backtrace
      error_class = begin
        case message
        when /Keyspace already exists/
        then KeyspaceExistsError
        else InvalidRequestError
        end
      end
      raise error_class, message, backtrace
    when ::Pelops::NotFoundException
      raise NotFoundError, e.cause.message, e.backtrace
    when ::Pelops::ApplicationException
      raise EurydiceError, e.cause.message, e.backtrace
    when Thrift::TTransportException
      raise TimeoutError, e.cause.message, e.backtrace
    end
  end
  raise e
end