mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
improve ajax error messages
This commit is contained in:
parent
fc159c3782
commit
a00cdab739
3 changed files with 30 additions and 12 deletions
|
@ -8,7 +8,8 @@ function fetchJson(verb, endpoint, body) {
|
|||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-csrf-token': window.booru.csrfToken
|
||||
'x-csrf-token': window.booru.csrfToken,
|
||||
'x-requested-with': 'xmlhttprequest'
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -24,7 +25,8 @@ function fetchHtml(endpoint) {
|
|||
return fetch(endpoint, {
|
||||
credentials: 'same-origin',
|
||||
headers: {
|
||||
'x-csrf-token': window.booru.csrfToken
|
||||
'x-csrf-token': window.booru.csrfToken,
|
||||
'x-requested-with': 'xmlhttprequest'
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -7,10 +7,18 @@ defmodule PhilomenaWeb.NotAuthorizedPlug do
|
|||
def call(conn), do: call(conn, nil)
|
||||
|
||||
def call(conn, _opts) do
|
||||
conn
|
||||
|> Controller.fetch_flash()
|
||||
|> Controller.put_flash(:error, "You can't access that page.")
|
||||
|> Controller.redirect(to: "/")
|
||||
|> Conn.halt()
|
||||
case conn.assigns.ajax? do
|
||||
true ->
|
||||
conn
|
||||
|> Conn.resp(:forbidden, "You can't access that page.")
|
||||
|> Conn.halt()
|
||||
|
||||
_false ->
|
||||
conn
|
||||
|> Controller.fetch_flash()
|
||||
|> Controller.put_flash(:error, "You can't access that page.")
|
||||
|> Controller.redirect(to: "/")
|
||||
|> Conn.halt()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,10 +7,18 @@ defmodule PhilomenaWeb.NotFoundPlug do
|
|||
def call(conn), do: call(conn, nil)
|
||||
|
||||
def call(conn, _opts) do
|
||||
conn
|
||||
|> Controller.fetch_flash()
|
||||
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|
||||
|> Controller.redirect(to: "/")
|
||||
|> Conn.halt()
|
||||
case conn.assigns.ajax? do
|
||||
true ->
|
||||
conn
|
||||
|> Conn.resp(:not_found, "Couldn't find what you were looking for!")
|
||||
|> Conn.halt()
|
||||
|
||||
false ->
|
||||
conn
|
||||
|> Controller.fetch_flash()
|
||||
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|
||||
|> Controller.redirect(to: "/")
|
||||
|> Conn.halt()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue