lib/triviacrack/api/common.rb in triviacrack-0.2.0 vs lib/triviacrack/api/common.rb in triviacrack-0.3.0

- old
+ new

@@ -17,11 +17,11 @@ # Raises TriviaCrack:Errors::RequestError if the request fails. def get(url, parameters: nil) response = Unirest.get "#{API_HOST}#{url}", parameters: parameters, headers: default_headers - check_response response + check_response url, response end # Internal: Makes a POST request to the Trivia Crack API using the set of # default headers. # @@ -32,11 +32,11 @@ # Raises TriviaCrack:Errors::RequestError if the request fails. def post(url, parameters: nil) response = Unirest.post "#{API_HOST}#{url}", parameters: parameters, headers: default_headers - check_response response + check_response url, response end private # Internal: The host name of the Trivia Crack API. @@ -61,13 +61,13 @@ # # response - Unirest response returned by the API. # # Returns the response object. # Raises TriviaCrack:Errors::RequestError if the request failed. - def check_response(response) + def check_response(url, response) if not response.code.between? 200, 299 - raise TriviaCrack::Errors::RequestError.new(response.code), - "Request to the Trivia Crack API failed." + raise TriviaCrack::Errors::RequestError.new(response.code, url, response.body), + "Request to #{API_HOST}#{url} failed with code #{response.code}." end response end end