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',
|
credentials: 'same-origin',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'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, {
|
return fetch(endpoint, {
|
||||||
credentials: 'same-origin',
|
credentials: 'same-origin',
|
||||||
headers: {
|
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), do: call(conn, nil)
|
||||||
|
|
||||||
def call(conn, _opts) do
|
def call(conn, _opts) do
|
||||||
conn
|
case conn.assigns.ajax? do
|
||||||
|> Controller.fetch_flash()
|
true ->
|
||||||
|> Controller.put_flash(:error, "You can't access that page.")
|
conn
|
||||||
|> Controller.redirect(to: "/")
|
|> Conn.resp(:forbidden, "You can't access that page.")
|
||||||
|> Conn.halt()
|
|> 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
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,10 +7,18 @@ defmodule PhilomenaWeb.NotFoundPlug do
|
||||||
def call(conn), do: call(conn, nil)
|
def call(conn), do: call(conn, nil)
|
||||||
|
|
||||||
def call(conn, _opts) do
|
def call(conn, _opts) do
|
||||||
conn
|
case conn.assigns.ajax? do
|
||||||
|> Controller.fetch_flash()
|
true ->
|
||||||
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|
conn
|
||||||
|> Controller.redirect(to: "/")
|
|> Conn.resp(:not_found, "Couldn't find what you were looking for!")
|
||||||
|> Conn.halt()
|
|> 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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue