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.



41
42
43
44
# File 'lib/travis/client/error.rb', line 41

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.



39
40
41
# File 'lib/travis/client/error.rb', line 39

def errors
  @errors
end

Instance Method Details

#parse_message(message) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/travis/client/error.rb', line 46

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