Exception: Textus::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, message, info: nil, details: {}, exit_code: 1, hint: nil) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
# File 'lib/textus/errors.rb', line 11

def initialize(code, message, info: nil, details: {}, exit_code: 1, hint: nil)
  super(message)
  @code = code
  @info = info || ErrorInfo.for(details:, exit_code:, hint:)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



9
10
11
# File 'lib/textus/errors.rb', line 9

def code
  @code
end

Instance Method Details

#detailsObject



17
# File 'lib/textus/errors.rb', line 17

def details = @info.details

#exit_codeObject



18
# File 'lib/textus/errors.rb', line 18

def exit_code = @info.exit_code

#hintObject



19
# File 'lib/textus/errors.rb', line 19

def hint = @info.hint

#to_envelopeObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/textus/errors.rb', line 21

def to_envelope
  env = {
    "protocol" => Textus::PROTOCOL,
    "ok" => false,
    "code" => @code,
    "message" => message,
    "details" => details,
  }
  env["hint"] = hint if hint
  env
end