Class: PartyResource::Exceptions::ConnectionError

Inherits:
Error
  • Object
show all
Defined in:
lib/party_resource/exceptions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ ConnectionError

Returns a new instance of ConnectionError.



41
42
43
44
# File 'lib/party_resource/exceptions.rb', line 41

def initialize(data=nil)
  super()
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



28
29
30
# File 'lib/party_resource/exceptions.rb', line 28

def data
  @data
end

Class Method Details

.build(data = nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/party_resource/exceptions.rb', line 30

def self.build(data=nil)
  klass = case data.code
    when 404 then ResourceNotFound
    when 422 then ResourceInvalid
    when 400..499 then ClientError
    when 500..599 then ServerError
    else self
  end
  klass.new(data)
end

Instance Method Details

#to_sObject



46
47
48
49
50
# File 'lib/party_resource/exceptions.rb', line 46

def to_s
  code = ''
  code = "#{data.code} " rescue nil
  "A #{code}connection error occured"
end