Exception: Particle::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Particle::Error
- Defined in:
- lib/particle/error.rb
Overview
Custom error class for rescuing from all Particle errors
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#short_message ⇒ Object
readonly
Returns the value of attribute short_message.
Class Method Summary collapse
-
.from_response(response) ⇒ Particle::Error
Returns the appropriate Particle::Error subclass based on status and response message.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(response = nil) ⇒ Error
Returns a new instance of Error.
28 29 30 31 32 |
# File 'lib/particle/error.rb', line 28 def initialize(response=nil) @response = response @short_message = super() end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
34 35 36 |
# File 'lib/particle/error.rb', line 34 def response @response end |
#short_message ⇒ Object (readonly)
Returns the value of attribute short_message.
35 36 37 |
# File 'lib/particle/error.rb', line 35 def @short_message end |
Class Method Details
.from_response(response) ⇒ Particle::Error
Returns the appropriate Particle::Error subclass based on status and response message
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/particle/error.rb', line 12 def self.from_response(response) status = response[:status].to_i body = response[:body].to_s if klass = case status when 400 then bad_request_error(body) when 401 then Particle::Unauthorized when 403 then Particle::Forbidden when 404 then Particle::NotFound when 408 then Particle::TimedOut when 500..599 then Particle::ServerError end klass.new(response) end end |