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.



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

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.



15
16
17
# File 'lib/travis/client/error.rb', line 15

def errors
  @errors
end

Instance Method Details

#parse_message(message) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/travis/client/error.rb', line 22

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