<commit_before>defmodule WhistlerNewsReader.PageController do
  use WhistlerNewsReader.Web, :controller

  require Logger

  def index(conn, _params) do
    template = if System.get_env("WEBPACK_ENV") === "hot" do
      webpack_devserver
    else
      webpack_file_system
    end

    conn |> html(template)
  end


  def webpack_devserver do
    case HTTPoison.get("http://localhost:4001/index.html") do
      {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
        body
      other ->
        Logger.error "PageController - error retrieving template from webpack devserver"
        other
    end
  end

  def webpack_file_system do
    File.read!("./priv/static/index.html")
  end
end<commit_msg>refactor(webpack integration): log error if template not found<commit_after>defmodule WhistlerNewsReader.PageController do
  use WhistlerNewsReader.Web, :controller

  require Logger

  def index(conn, _params) do
    template = if System.get_env("WEBPACK_ENV") === "hot" do
      webpack_devserver
    else
      webpack_file_system
    end

    conn |> html(template)
  end


  def webpack_devserver do
    case HTTPoison.get("http://localhost:4001/index.html") do
      {:ok, %HTTPoison.Response{status_code: 200, body: body}} ->
        body
      other ->
        Logger.error "PageController - error retrieving template from webpack devserver"
        other
    end
  end

  def webpack_file_system do
    case File.read("./priv/static/index.html") do
      {:ok, body}      ->
        body
      {:error, reason} ->
        Logger.error "PageController - error retrieving template from local filesystem #{reason}. Did you run the webpack build?"
        reason
    end
  end
end
{'fraction_non_alphanumeric': 0.09139150943396226, 'fraction_numerical': 0.008254716981132075, 'mean_word_length': 2.883295194508009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7467980', 'n_tokens_mistral': 530, 'n_tokens_neox': 508, 'n_words': 138}