dossiers: rescue RecordNotFound only for procedures

This ensures that we won't rescue an `ActiveRecord::RecordNotFound`
exception related to another object.
This commit is contained in:
Pierre de La Morinerie 2020-01-06 11:53:20 +00:00
parent 7f5b0d8bf3
commit 5b2311c851

View file

@ -220,10 +220,15 @@ module Users
def new
erase_user_location!
if params[:brouillon]
procedure = Procedure.brouillon.find(params[:procedure_id])
else
procedure = Procedure.publiees.find(params[:procedure_id])
begin
if params[:brouillon]
procedure = Procedure.brouillon.find(params[:procedure_id])
else
procedure = Procedure.publiees.find(params[:procedure_id])
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.procedure_not_found')
return redirect_to url_for dossiers_path
end
dossier = Dossier.create!(groupe_instructeur: procedure.defaut_groupe_instructeur, user: current_user, state: Dossier.states.fetch(:brouillon))
@ -237,10 +242,6 @@ module Users
else
redirect_to siret_dossier_path(id: dossier.id)
end
rescue ActiveRecord::RecordNotFound
flash.alert = t('errors.messages.procedure_not_found')
redirect_to url_for dossiers_path
end
def dossier_for_help