lib/ecoportal/api/v1/people.rb in ecoportal-api-0.8.2 vs lib/ecoportal/api/v1/people.rb in ecoportal-api-0.8.3

- old
+ new

@@ -35,11 +35,11 @@ cursor_id = nil; results = 0 puts "\n" unless silent loop do params.update(cursor_id: cursor_id) if cursor_id response = client.get("/people", params: params) - body = body_data(response.body) + body = response && body_data(response.body) raise "Request failed - Status #{response.status}: #{body}" unless response.success? unless silent || (total = body["total_results"]) == 0 results += body["results"].length percent = results * 100 / total @@ -137,11 +137,12 @@ status = wait_for_job_completion(job_id) if status&.complete? operation.process_response job_result(job_id, operation) else - raise "Job `#{job_id}` not complete. Probably timeout after #{JOB_TIMEOUT} seconds. Current status: #{status}" + msg = "Job `#{job_id}` not complete. Probably timeout after #{JOB_TIMEOUT} seconds. Current status: #{status}" + raise API::Errors::TimeOut.new msg end end # Creates a new `Person` object. # @return [Person] new empty person object of the current version. @@ -152,12 +153,12 @@ private JobStatus = Struct.new(:id, :complete?, :errored?, :progress) def job_status(job_id) response = client.get("/people/job/#{CGI.escape(job_id)}/status") - body = body_data(response.body) - raise "Status error" unless response.success? + body = response && body_data(response.body) + raise "Status error (#{response.status}) - Errors: #{body}" unless response.success? JobStatus.new( body["id"], body["complete"], body["errored"], body["progress"] @@ -188,11 +189,12 @@ def create_job(operation) job_id = nil client.without_response_logging do client.post("/people/job", data: operation.as_json).tap do |response| - job_id = body_data(response.body)["id"] + job_id = body_data(response.body)["id"] if response.success? end + raise "Could not create job - Error (#{response.status}): #{body_data(response.body)}" unless job_id end job_id end # Hook for other api versions to obtain the raw data of a response