Exception: HCloud::Errors::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Error

Returns a new instance of Error.



8
9
10
11
12
# File 'lib/hcloud/errors.rb', line 8

def initialize(data = {})
  @data = data

  super([data[:message], full_messages&.join("\n")].compact.join("\n\n"))
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/hcloud/errors.rb', line 6

def data
  @data
end

Instance Method Details

#full_messagesObject



14
15
16
17
18
19
20
21
22
# File 'lib/hcloud/errors.rb', line 14

def full_messages
  return unless data[:details]

  data[:details][:fields].flat_map do |field|
    Array(field.fetch(:messages, data[:message])).map do |detail|
      "#{field[:name]} #{detail}"
    end
  end
end