Exception: CleverSDK::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/clever_sdk/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_to_takeObject

Returns the value of attribute action_to_take.



21
22
23
# File 'lib/clever_sdk/error.rb', line 21

def action_to_take
  @action_to_take
end

#codeObject

Returns the value of attribute code.



21
22
23
# File 'lib/clever_sdk/error.rb', line 21

def code
  @code
end

#meaningObject

Returns the value of attribute meaning.



21
22
23
# File 'lib/clever_sdk/error.rb', line 21

def meaning
  @meaning
end

#responseObject

Returns the value of attribute response.



21
22
23
# File 'lib/clever_sdk/error.rb', line 21

def response
  @response
end

Class Method Details

.handle(faraday_response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/clever_sdk/error.rb', line 5

def self.handle(faraday_response)
  explanation = CleverSDK::Api::Response.status_code_explanations[faraday_response.status]

  error_obj = if explanation.nil?
    new
  else
    new([explanation[:meaning], explanation[:action_to_take]].join(": "))
  end

  error_obj.response = faraday_response
  error_obj.code = faraday_response.status
  error_obj.meaning = explanation[:meaning] if explanation
  error_obj.action_to_take = explanation[:action_to_take] if explanation
  error_obj
end

Instance Method Details

#intitialize(message = "Unknown API error") ⇒ Object



23
24
25
# File 'lib/clever_sdk/error.rb', line 23

def intitialize(message = "Unknown API error")
  super(message)
end