lib/crunchbase/utilities/request.rb in crunchbase4-0.1.9 vs lib/crunchbase/utilities/request.rb in crunchbase4-0.2.0

- old
+ new

@@ -42,13 +42,15 @@ faraday.response :json faraday.request :curl, ::Logger.new(STDOUT), :warn if debug_mode? faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode? end.post(uri, args) - return response.body if response.status == 200 + resp_body = response.body + resp_status = response.status + return resp_body if resp_status == 200 - raise Error, response.body[0]['message'] + raise Error, resp_body.is_a?(Array) ? resp_body[0]['message'] : resp_body['error'] end private def fetch_request(uri, *args) @@ -56,12 +58,14 @@ faraday.adapter Faraday.default_adapter faraday.response :json faraday.response :logger, ::Logger.new(STDOUT), bodies: true if debug_mode? end.get(uri, *args) - return response.body if response.status == 200 + resp_body = response.body + resp_status = response.status + return resp_body if resp_status == 200 - raise Error, response.status == 400 ? response.body[0]['message'] : response.body['error'] + raise Error, resp_body.is_a?(Array) ? resp_body[0]['message'] : resp_body['error'] end def debug_mode? Crunchbase.config.debug || false end