Exception: Travis::Client::ValidationFailed

Inherits:
Error
  • Object
show all
Defined in:
lib/travis/client/error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, *args) ⇒ ValidationFailed

Returns a new instance of ValidationFailed.



20
21
22
23
# File 'lib/travis/client/error.rb', line 20

def initialize(message = nil, *args)
  message = parse_message(message) if message
  super(message, *args)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



18
19
20
# File 'lib/travis/client/error.rb', line 18

def errors
  @errors
end

Instance Method Details

#parse_message(message) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/travis/client/error.rb', line 25

def parse_message(message)
  response   = JSON.load(message)
  message    = response['message'].to_s
  if @errors = response['errors'] and @errors.any?
    readable = @errors.map { |e| "#{e['field']}: #{e['code'].gsub('_', ' ')}" }
    message += " (#{readable.join(', ')})"
  end
  message
rescue JSON::ParserError
  message
end