demarches-normaliennes/app/models/concerns/rna_champ_association_fetchable_concern.rb
2023-02-27 14:31:58 +01:00

16 lines
452 B
Ruby

module RNAChampAssociationFetchableConcern
extend ActiveSupport::Concern
def fetch_association!(rna)
data = APIEntreprise::RNAAdapter.new(rna, procedure_id).to_params
update!(data: data, value: rna)
nil
rescue APIEntreprise::API::Error, ActiveRecord::RecordInvalid => error
update(data: nil, value: nil)
if error.try(:network_error?) && !APIEntrepriseService.api_up?
:network_error
else
nil
end
end
end