Merge pull request #8868 from tchak/fix-api-entreprise-adapter

fix(api-entreprise): do not crash when siret not found
This commit is contained in:
Paul Chavard 2023-04-06 10:00:59 +00:00 committed by GitHub
commit f9b7859bf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 10 deletions

View file

@ -6,17 +6,25 @@ class APIEntreprise::EntrepriseAdapter < APIEntreprise::Adapter
end
def process_params
params = data_source[:entreprise]&.slice(*attr_to_fetch)
params[:etat_administratif] = map_etat_administratif(data_source)
params = data_source[:entreprise]
return {} if params.nil?
if params.present? && valid_params?(params)
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime if params[:date_creation].present?
if params[:raison_sociale].present? && is_individual_entreprise?(params[:forme_juridique_code])
params[:raison_sociale] = humanize_raison_sociale(params[:raison_sociale])
Sentry.with_scope do |scope|
scope.set_tags(siret: @siret)
scope.set_extras(source: params)
params = params.slice(*attr_to_fetch)
params[:etat_administratif] = map_etat_administratif(data_source)
if params.present? && valid_params?(params)
params[:date_creation] = Time.zone.at(params[:date_creation]).to_datetime if params[:date_creation].present?
if params[:raison_sociale].present? && is_individual_entreprise?(params[:forme_juridique_code])
params[:raison_sociale] = humanize_raison_sociale(params[:raison_sociale])
end
params.transform_keys { |k| :"entreprise_#{k}" }
else
{}
end
params.transform_keys { |k| :"entreprise_#{k}" }
else
{}
end
end

View file

@ -15,12 +15,13 @@ class APIEntreprise::RNAAdapter < APIEntreprise::Adapter
def process_params
params = data_source[:association]
return {} if params.nil?
Sentry.with_scope do |scope|
scope.set_tags(siret: @siret)
scope.set_extras(source: params)
params = params&.slice(*attr_to_fetch) if @depreciated
params = params.slice(*attr_to_fetch) if @depreciated
params[:rna] = data_source.dig(:association, :id)
if params[:rna].present? && valid_params?(params)