Exception: TriCoreDB::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/tricoredb/errors.rb

Overview

Base class for every failure raised by this gem.

Branch on #code, never on the message: the message is prose the server is free to reword, the code is contract.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, code: nil, leader_hint: nil) ⇒ Error

Returns a new instance of Error.

Parameters:

  • message (String, nil) (defaults to: nil)
  • code (String, nil) (defaults to: nil)
  • leader_hint (String, nil) (defaults to: nil)


20
21
22
23
24
# File 'lib/tricoredb/errors.rb', line 20

def initialize(message = nil, code: nil, leader_hint: nil)
  super(message)
  @code = code
  @leader_hint = leader_hint
end

Instance Attribute Details

#code ⇒ String? (readonly)

Returns the machine-readable reason, when the server sent one.

Returns:

  • (String, nil) —

    the machine-readable reason, when the server sent one



13
14
15
# File 'lib/tricoredb/errors.rb', line 13

def code
  @code
end

#leader_hint ⇒ String? (readonly)

Returns a host:port of the current leader, only alongside not_leader.

Returns:

  • (String, nil) —

    a host:port of the current leader, only alongside not_leader



15
16
17
# File 'lib/tricoredb/errors.rb', line 15

def leader_hint
  @leader_hint
end

Instance Method Details

#redirect? ⇒ Boolean

Whether the request was right but reached a node that is not the leader.

The driver never follows #leader_hint on its own: the address may not be reachable from this client, a new connection must authenticate again, and an open session transaction cannot move to another node at all.

Returns:

  • (Boolean)


33
34
35
# File 'lib/tricoredb/errors.rb', line 33

def redirect?
  code == NOT_LEADER
end