add nicer lookup error handlers

This commit is contained in:
byte[] 2019-12-01 21:30:58 -05:00
parent ea29cef2a1
commit 3046da7c67
5 changed files with 33 additions and 3 deletions

View file

@ -44,7 +44,9 @@ config :elastix,
json_codec: Jason
config :canary,
repo: Philomena.Repo
repo: Philomena.Repo,
unauthorized_handler: {PhilomenaWeb.NotAuthorizedPlug, :call},
not_found_handler: {PhilomenaWeb.NotFoundPlug, :call}
# Configures the endpoint
config :philomena, PhilomenaWeb.Endpoint,

View file

@ -0,0 +1,14 @@
defmodule PhilomenaWeb.NotAuthorizedPlug do
alias Phoenix.Controller
alias Plug.Conn
def init([]), do: []
def call(conn), do: call(conn, nil)
def call(conn, _opts) do
conn
|> Controller.put_flash(:error, "You can't access that page.")
|> Controller.redirect(to: conn.assigns.referrer)
|> Conn.halt()
end
end

View file

@ -0,0 +1,14 @@
defmodule PhilomenaWeb.NotFoundPlug do
alias Phoenix.Controller
alias Plug.Conn
def init([]), do: []
def call(conn), do: call(conn, nil)
def call(conn, _opts) do
conn
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|> Controller.redirect(to: conn.assigns.referrer)
|> Conn.halt()
end
end

View file

@ -38,7 +38,7 @@
picture
img alt=hover_text
- {:filtered_video, hover_text}
- {:filtered_video, hover_text} ->
video autoplay="autoplay" muted="muted" loop="loop" playsinline="playsinline"
img alt=hover_text

View file

@ -49,7 +49,7 @@ defmodule Search.Evaluator do
query_re = wildcard_to_regex(query_val)
wrap(doc[atomify(term)])
|> Enum.any?(&Regex.match?(query_re, &1))
|> Enum.any?(&Regex.match?(query_re, &1 || ""))
end
def hits?(doc, %{match_phrase: phrase_query}) do