[API Carto]: use typhoeus and correctly handle errors
This commit is contained in:
parent
d52f600b2e
commit
08b1a0f90d
1 changed files with 8 additions and 5 deletions
|
@ -12,11 +12,14 @@ class ApiCarto::API
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.call(url, geojson)
|
def self.call(url, geojson)
|
||||||
params = geojson.to_s
|
response = Typhoeus.post(url, body: geojson.to_s, headers: { 'content-type' => 'application/json' })
|
||||||
RestClient.post(url, params, content_type: 'application/json')
|
|
||||||
|
|
||||||
rescue RestClient::InternalServerError, RestClient::BadGateway, RestClient::GatewayTimeout, RestClient::ServiceUnavailable => e
|
if response.success?
|
||||||
Rails.logger.error "[ApiCarto] Error on #{url}: #{e}"
|
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
|
raise RestClient::ResourceNotFound
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue