feature (errorpage): ux for error page

This commit is contained in:
MickaelK 2024-12-29 18:44:01 +11:00
parent b19d7bba24
commit 4baeae2f59
2 changed files with 5 additions and 3 deletions

View file

@ -7,6 +7,7 @@ export default function(opts) {
else if (typeof opts !== "object") throw new Error("unsupported call");
if (!opts.headers) opts.headers = {};
if (!opts.responseType) opts.responseType = "text";
opts.headers["X-Requested-With"] = "XmlHttpRequest";
if (window.BEARER_TOKEN) opts.headers["Authorization"] = `Bearer ${window.BEARER_TOKEN}`;

View file

@ -1,5 +1,5 @@
import { createElement, createRender } from "../lib/skeleton/index.js";
import { toHref, fromHref } from "../lib/skeleton/router.js";
import { toHref, fromHref, navigate } from "../lib/skeleton/router.js";
import { forwardURLParams } from "../lib/path.js";
import rxjs, { effect, applyMutation } from "../lib/rx.js";
import { qs } from "../lib/dom.js";
@ -20,8 +20,9 @@ export default function(render) {
return function(err) {
const [msg, trace] = processError(err);
const shouldRedirectLogin = err instanceof AjaxError && err.err().status === 401;
let link = forwardURLParams(calculateBacklink(fromHref(window.location.pathname)), ["share"]);
if (err instanceof AjaxError && err.err().status === 401) {
if (shouldRedirectLogin) {
link = fromHref("/login?next=" + encodeURIComponent(forwardURLParams(fromHref(window.location.pathname), ["share"])));
}
const $page = createElement(`
@ -57,7 +58,7 @@ export default function(render) {
const $refresh = qs($page, "button[data-bind=\"refresh\"]");
if (shouldHideRefreshButton) $refresh.remove();
else effect(rxjs.fromEvent($refresh, "click").pipe(
rxjs.tap(() => location.reload())
rxjs.tap(() => shouldRedirectLogin ? navigate(link) : location.reload()),
));
return rxjs.EMPTY;