mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 13:11:46 +08:00
feature (error): nicer error page
This commit is contained in:
@ -9,11 +9,6 @@ import { AjaxError, ApplicationError } from "../lib/error.js";
|
|||||||
|
|
||||||
import "../components/icon.js";
|
import "../components/icon.js";
|
||||||
|
|
||||||
const strToHTML = (str) => str
|
|
||||||
.replaceAll("<", "<")
|
|
||||||
.replaceAll(">", ">")
|
|
||||||
.replaceAll(" ", " ");
|
|
||||||
|
|
||||||
export default function(render) {
|
export default function(render) {
|
||||||
let hasBack = true;
|
let hasBack = true;
|
||||||
if (!render) {
|
if (!render) {
|
||||||
@ -25,7 +20,10 @@ export default function(render) {
|
|||||||
return function(err) {
|
return function(err) {
|
||||||
const [msg, trace] = processError(err);
|
const [msg, trace] = processError(err);
|
||||||
|
|
||||||
const link = forwardURLParams(calculateBacklink(fromHref(window.location.pathname)), ["share"]);
|
let link = forwardURLParams(calculateBacklink(fromHref(window.location.pathname)), ["share"]);
|
||||||
|
if (err instanceof AjaxError && err.err().status === 401) {
|
||||||
|
link = fromHref("/login?next=" + encodeURIComponent(forwardURLParams(fromHref(window.location.pathname), ["share"])));
|
||||||
|
}
|
||||||
const $page = createElement(`
|
const $page = createElement(`
|
||||||
<div>
|
<div>
|
||||||
<style>${css}</style>
|
<style>${css}</style>
|
||||||
@ -40,7 +38,7 @@ export default function(render) {
|
|||||||
<p>
|
<p>
|
||||||
<button class="light" data-bind="details">${t("More details")}</button>
|
<button class="light" data-bind="details">${t("More details")}</button>
|
||||||
<button class="primary" data-bind="refresh">${t("Reload")}</button>
|
<button class="primary" data-bind="refresh">${t("Reload")}</button>
|
||||||
<pre class="hidden"><code>${strToHTML(trace)}</code></pre>
|
<pre class="hidden"><code>${formatTrace(trace)}</code></pre>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -91,6 +89,17 @@ trace: ${err.stack || "N/A"}`;
|
|||||||
return [msg, trace.trim()];
|
return [msg, trace.trim()];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatTrace(str) {
|
||||||
|
return str
|
||||||
|
.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">")
|
||||||
|
.replaceAll(" ", " ")
|
||||||
|
.split("\n")
|
||||||
|
.map((line) => line.indexOf("/lib/vendor/") === -1 ? line : `<span style="opacity:0.25">${line}</span>`)
|
||||||
|
.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const css = `
|
const css = `
|
||||||
.error-page {
|
.error-page {
|
||||||
width: 80%;
|
width: 80%;
|
||||||
|
|||||||
Reference in New Issue
Block a user