mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +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,6 +7,13 @@ 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
|
||||||
|
case conn.assigns.ajax? do
|
||||||
|
true ->
|
||||||
|
conn
|
||||||
|
|> Conn.resp(:forbidden, "You can't access that page.")
|
||||||
|
|> Conn.halt()
|
||||||
|
|
||||||
|
_false ->
|
||||||
conn
|
conn
|
||||||
|> Controller.fetch_flash()
|
|> Controller.fetch_flash()
|
||||||
|> Controller.put_flash(:error, "You can't access that page.")
|
|> Controller.put_flash(:error, "You can't access that page.")
|
||||||
|
@ -14,3 +21,4 @@ defmodule PhilomenaWeb.NotAuthorizedPlug do
|
||||||
|> Conn.halt()
|
|> Conn.halt()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -7,6 +7,13 @@ 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
|
||||||
|
case conn.assigns.ajax? do
|
||||||
|
true ->
|
||||||
|
conn
|
||||||
|
|> Conn.resp(:not_found, "Couldn't find what you were looking for!")
|
||||||
|
|> Conn.halt()
|
||||||
|
|
||||||
|
false ->
|
||||||
conn
|
conn
|
||||||
|> Controller.fetch_flash()
|
|> Controller.fetch_flash()
|
||||||
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|
|> Controller.put_flash(:error, "Couldn't find what you were looking for!")
|
||||||
|
@ -14,3 +21,4 @@ defmodule PhilomenaWeb.NotFoundPlug do
|
||||||
|> Conn.halt()
|
|> Conn.halt()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in a new issue