improve ajax error messages

This commit is contained in:
byte[] 2020-09-27 23:53:14 -04:00
parent fc159c3782
commit a00cdab739
3 changed files with 30 additions and 12 deletions

View file

@ -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'
},
});
}

View file

@ -7,10 +7,18 @@ defmodule PhilomenaWeb.NotAuthorizedPlug do
def call(conn), do: call(conn, nil)
def call(conn, _opts) do
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

View file

@ -7,10 +7,18 @@ defmodule PhilomenaWeb.NotFoundPlug do
def call(conn), do: call(conn, nil)
def call(conn, _opts) do
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