Exception: ChatWork::ChatWorkError
- Inherits:
-
StandardError
- Object
- StandardError
- ChatWork::ChatWorkError
- Defined in:
- lib/chatwork/chatwork_error.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#error_response ⇒ Object
readonly
Returns the value of attribute error_response.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(message, status = nil, error_response = nil) ⇒ ChatWorkError
constructor
A new instance of ChatWorkError.
Constructor Details
#initialize(message, status = nil, error_response = nil) ⇒ ChatWorkError
Returns a new instance of ChatWorkError.
25 26 27 28 |
# File 'lib/chatwork/chatwork_error.rb', line 25 def initialize(, status = nil, error_response = nil) @status, @error_response = status, error_response super() end |
Instance Attribute Details
#error_response ⇒ Object (readonly)
Returns the value of attribute error_response.
23 24 25 |
# File 'lib/chatwork/chatwork_error.rb', line 23 def error_response @error_response end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
22 23 24 |
# File 'lib/chatwork/chatwork_error.rb', line 22 def status @status end |
Class Method Details
.from_response(status, body) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/chatwork/chatwork_error.rb', line 5 def self.from_response(status, body) # HTTP status 204 don't have body. return APIError.new(status, "") if status == 204 hash = begin JSON.load(body) rescue JSON::ParserError => e return ChatWork::APIConnectionError.new("Response JSON is broken. #{e.}: #{body}", e) end unless hash['errors'] return APIConnectionError.new("Invalid response #{body}") end APIError.new(status, hash["errors"]) end |