carto: present API InternalServerError to the user, instead of failing

This commit is contained in:
Pierre de La Morinerie 2019-01-24 18:30:14 +01:00
parent 4de069d436
commit 803364490d
4 changed files with 60 additions and 32 deletions

View file

@ -74,5 +74,9 @@ class Champs::CarteController < ApplicationController
if @champ.persisted?
@champ.save
end
rescue RestClient::ResourceNotFound
flash.alert = 'Les données cartographiques sont temporairement indisponibles. Réessayez dans un instant.'
response.status = 503
end
end

View file

@ -13,10 +13,10 @@ class ApiCarto::API
def self.call(url, geojson)
params = geojson.to_s
RestClient.post(url, params, content_type: 'application/json')
rescue RestClient::InternalServerError
rescue RestClient::InternalServerError => e
Rails.logger.error "[ApiCarto] Error on #{url}: #{e}"
raise RestClient::ResourceNotFound
end
end

View file

@ -1,3 +1,5 @@
<%= render_flash(timeout: 5000, fixed: true) %>
<%= render_to_element("#{@selector} + .geo-areas",
partial: 'shared/champs/carte/geo_areas',
locals: { champ: @champ, error: @error }) %>