Exception: Twilic::Core::Errors::TwilicError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, byte: nil, msg: nil, ref_kind: nil, ref_id: nil) ⇒ TwilicError

Returns a new instance of TwilicError.



17
18
19
20
21
22
23
24
# File 'lib/twilic/core/errors.rb', line 17

def initialize(kind, byte: nil, msg: nil, ref_kind: nil, ref_id: nil)
  @kind = kind
  @byte = byte
  @msg = msg
  @ref_kind = ref_kind
  @ref_id = ref_id
  super(message)
end

Instance Attribute Details

#byteObject (readonly)

Returns the value of attribute byte.



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

def byte
  @byte
end

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#msgObject (readonly)

Returns the value of attribute msg.



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

def msg
  @msg
end

#ref_idObject (readonly)

Returns the value of attribute ref_id.



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

def ref_id
  @ref_id
end

#ref_kindObject (readonly)

Returns the value of attribute ref_kind.



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

def ref_kind
  @ref_kind
end

Instance Method Details

#messageObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/twilic/core/errors.rb', line 26

def message
  case kind
  when UNEXPECTED_EOF
    "unexpected end of input"
  when INVALID_KIND
    format("invalid message kind: 0x%02x", byte)
  when INVALID_TAG
    format("invalid value tag: 0x%02x", byte)
  when INVALID_DATA
    "invalid data: #{msg}"
  when UTF8
    "utf8 decode error"
  when UNKNOWN_REFERENCE
    "unknown reference: #{ref_kind}=#{ref_id}"
  when STATELESS_RETRY_REQUIRED
    "stateless retry required for reference: #{ref_kind}=#{ref_id}"
  else
    "twilic error"
  end
end