Exception: SimpleSpark::Exceptions::Error
- Inherits:
-
StandardError
- Object
- StandardError
- SimpleSpark::Exceptions::Error
- Defined in:
- lib/simple_spark/exceptions.rb
Overview
Adding an object to the exception to pass errors back begin
raise Error.new({ id: '1' }), "a message"
rescue Error => e
puts e. # => "a message"
puts e.object # => { id: '1' }
end
Direct Known Subclasses
BadRequest, GatewayTimeoutExceeded, InvalidConfiguration, NotFound, ThrottleLimitExceeded, UnprocessableEntity
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(object = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(object = nil) ⇒ Error
Returns a new instance of Error.
13 14 15 |
# File 'lib/simple_spark/exceptions.rb', line 13 def initialize(object = nil) @object = object end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
11 12 13 |
# File 'lib/simple_spark/exceptions.rb', line 11 def object @object end |
Class Method Details
.fail_with_exception_for_status(status, errors) ⇒ Object
17 18 19 20 |
# File 'lib/simple_spark/exceptions.rb', line 17 def self.fail_with_exception_for_status(status, errors) exception = status_codes[status.to_s] || status_codes['default'] fail exception.new(errors), errors.map { |e| "#{e['message']} #{status} (Error Code: #{e['code']})" + (e['description'] ? ": #{e['description']}" : '') }.join(', ') end |
.status_codes ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/simple_spark/exceptions.rb', line 22 def self.status_codes { 'default' => Exceptions::UnprocessableEntity, '400' => Exceptions::BadRequest, '404' => Exceptions::NotFound, '422' => Exceptions::UnprocessableEntity, '420' => Exceptions::ThrottleLimitExceeded, '429' => Exceptions::ThrottleLimitExceeded } end |