fix(api-entreprise): do not crash when siret not found

This commit is contained in:
Paul Chavard 2023-04-05 18:38:13 +02:00
parent 6511836f2d
commit d1d5bc2e67
2 changed files with 19 additions and 10 deletions

View file

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

View file

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