lib/chatwork/chatwork_error.rb in chatwork-0.5.0 vs lib/chatwork/chatwork_error.rb in chatwork-0.6.0

- old
+ new

@@ -1,34 +1,24 @@ -require 'json' module ChatWork class ChatWorkError < StandardError - def self.from_response(status, body, headers) - # 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.message}: #{body}", e) - end - unless hash['errors'] + unless body["errors"] return APIConnectionError.new("Invalid response #{body}") end - if headers.has_key?('WWW-Authenticate') - return AuthenticateError.new(headers['WWW-Authenticate'], status, hash['errors']) + if headers.has_key?("WWW-Authenticate") + return AuthenticateError.new(headers["WWW-Authenticate"], status, body["errors"]) end - APIError.new(status, hash['errors']) + APIError.new(status, body["errors"]) end attr_reader :status attr_reader :error_response def initialize(message, status = nil, error_response = nil) - @status, @error_response = status, error_response + @status = status + @error_response = error_response super(message) end end class APIConnectionError < ChatWorkError