Module: Fog::Hetznercloud::Errors
- Defined in:
- lib/fog/hetznercloud/errors.rb
Class Method Summary collapse
Class Method Details
.decode_error(error) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/fog/hetznercloud/errors.rb', line 4 def self.decode_error(error) body = begin Fog::JSON.decode(error.response.body) rescue Fog::JSON::DecodeError nil end return if body.nil? code = body['error']['code'] = body['error']['message'] details = body['error']['details'] return if code.nil? || .nil? unless details.nil? << "\n" << format_details(details) end { code: code, message: } end |
.format_details(details) ⇒ Object
27 28 29 |
# File 'lib/fog/hetznercloud/errors.rb', line 27 def self.format_details(details) details.map { |field, msgs| format_field(field, msgs) }.join("\n") end |
.format_field(field, msgs) ⇒ Object
31 32 33 34 |
# File 'lib/fog/hetznercloud/errors.rb', line 31 def self.format_field(field, msgs) msgs = msgs.map { |msg| "\t\t- #{msg}" } "\t#{field}:\n#{msgs.join("\n")}" end |