mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
add nicer lookup error handlers
This commit is contained in:
parent
ea29cef2a1
commit
3046da7c67
5 changed files with 33 additions and 3 deletions
|
@ -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,
|
||||
|
|
14
lib/philomena_web/plugs/not_authorized_plug.ex
Normal file
14
lib/philomena_web/plugs/not_authorized_plug.ex
Normal 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
|
14
lib/philomena_web/plugs/not_found_plug.ex
Normal file
14
lib/philomena_web/plugs/not_found_plug.ex
Normal 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
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue