lib/ods_wrapper/data/siret.rb in ods_wrapper-1.0.2 vs lib/ods_wrapper/data/siret.rb in ods_wrapper-1.0.3

- old
+ new

@@ -24,11 +24,14 @@ rows: 25 } end end - result = HTTParty.get(OdsWrapper::ODS_URL, query:query).body + response = HTTParty.get(OdsWrapper::ODS_URL, query:query) + return JSON.generate( { error: 'Server temporarily inaccessible' } ) if response.code >= 500 && response.code <= 599 + + result = response.body hash = JSON.parse(result) if (hash.dig('nhits') || 0) > 0 response = format_response(hash) else @@ -42,10 +45,13 @@ query = { dataset: OdsWrapper::Siret::DATASET, q: "siret:#{siret}" } - result = HTTParty.get(OdsWrapper::ODS_URL, query:query).body + response = HTTParty.get(OdsWrapper::ODS_URL, query:query) + return JSON.generate( { error: 'Server temporarily inaccessible' } ) if response.code >= 500 && response.code <= 599 + + result = response.body hash = JSON.parse(result) if (hash.dig('nhits') || 0) > 0 response = format_response(hash) else