Skip to content

Commit

Permalink
Respond a 404 for files not yet generated
Browse files Browse the repository at this point in the history
We were raising an exception instead.

See #2350
  • Loading branch information
matiasgarciaisaia committed Nov 14, 2024
1 parent d5ceb9a commit 6c1d42e
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/ask_web/controllers/respondent_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -749,12 +749,20 @@ defmodule AskWeb.RespondentController do
end

defp serve_file(conn, survey, file_type) do
file_url = SurveyResults.file_path(survey, file_type)
file_path = SurveyResults.file_path(survey, file_type)

conn
|> send_download({:file, file_url})
|> send_download_if_exists(file_path, File.exists?(file_path))
end

defp send_download_if_exists(conn, file_path, true), do:
conn
|> send_download({:file, file_path})

defp send_download_if_exists(conn, _file_path, false), do:
conn
|> send_resp(404, "File not found")

def results_csv(conn, %{"project_id" => project_id, "survey_id" => survey_id} = params) do
project = load_project(conn, project_id)
survey = load_survey(project, survey_id)
Expand Down

0 comments on commit 6c1d42e

Please sign in to comment.