Merge pull request #4479 from tchak/fix-carto-errors

[API Carto]: use typhoeus and correctly handle errors
This commit is contained in:
Paul Chavard 2019-11-06 11:20:08 +01:00 committed by GitHub
commit 88a4befbc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,11 +12,14 @@ class ApiCarto::API
private
def self.call(url, geojson)
params = geojson.to_s
RestClient.post(url, params, content_type: 'application/json')
response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' })
rescue RestClient::InternalServerError, RestClient::BadGateway, RestClient::GatewayTimeout, RestClient::ServiceUnavailable => e
Rails.logger.error "[ApiCarto] Error on #{url}: #{e}"
if response.success?
response.body
else
message = response.code == 0 ? response.return_message : response.code.to_s
Rails.logger.error "[ApiCarto] Error on #{url}: #{message}"
raise RestClient::ResourceNotFound
end
end
end