class SimpleSpark::Exceptions::Error

Adding an object to the exception to pass errors back begin

raise Error.new({ id: '1' }), "a message"

rescue Error => e

puts e.message # => "a message"
puts e.object # => { id: '1' }

end

Attributes

object[R]
results[R]

Public Class Methods

fail_with_exception_for_status(status, errors, results) click to toggle source
# File lib/simple_spark/exceptions.rb, line 22
def self.fail_with_exception_for_status(status, errors, results)
  exception = status_codes[status.to_s] || status_codes['default']
  fail exception.new(errors, results), errors.map { |e| "#{e['message']} #{status} (Error Code: #{e['code']})" + (e['description'] ? ": #{e['description']}" : '') }.join(', ')
end
new(object = nil, results = {}) click to toggle source
# File lib/simple_spark/exceptions.rb, line 13
def initialize(object = nil, results = {})
  @object = object
  @results = results
end
status_codes() click to toggle source
# File lib/simple_spark/exceptions.rb, line 27
def self.status_codes
  {
    'default' => Exceptions::UnprocessableEntity,
    '400' => Exceptions::BadRequest,
    '404' => Exceptions::NotFound,
    '422' => Exceptions::UnprocessableEntity,
    '420' => Exceptions::ThrottleLimitExceeded,
    '429' => Exceptions::ThrottleLimitExceeded
  }
end

Public Instance Methods

transmission_id() click to toggle source
# File lib/simple_spark/exceptions.rb, line 18
def transmission_id
  results['id']
end