mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 23:30:00 -04:00
chore: enhance worker error message readability and details.
This commit is contained in:
parent
3015dff77d
commit
4455930d28
2 changed files with 57 additions and 7 deletions
|
@ -9,6 +9,14 @@ export function errorTemplate(trace: string, fetchedURL: string) {
|
|||
reload.addEventListener("click", () => location.reload());
|
||||
version.textContent = ${JSON.stringify($scramjet.version.version)};
|
||||
build.textContent = ${JSON.stringify($scramjet.version.build)};
|
||||
|
||||
document.getElementById('copy-button').addEventListener('click', async () => {
|
||||
const text = document.getElementById('errorTrace').value;
|
||||
await navigator.clipboard.writeText(text);
|
||||
const btn = document.getElementById('copy-button');
|
||||
btn.textContent = 'Copied!';
|
||||
setTimeout(() => btn.textContent = 'Copy', 2000);
|
||||
});
|
||||
`;
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
|
@ -54,6 +62,7 @@ export function errorTemplate(trace: string, fetchedURL: string) {
|
|||
resize: none;
|
||||
height: 20em;
|
||||
text-align: left;
|
||||
color: red;
|
||||
font-family: var(--font-monospace);
|
||||
}
|
||||
|
||||
|
@ -94,10 +103,11 @@ export function errorTemplate(trace: string, fetchedURL: string) {
|
|||
}
|
||||
|
||||
#version-wrapper {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
width: auto;
|
||||
text-align: right;
|
||||
position: absolute;
|
||||
bottom: 0.2rem;
|
||||
top: 0.5rem;
|
||||
right: 0.5rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--shore)!important;
|
||||
i {
|
||||
|
@ -107,6 +117,26 @@ export function errorTemplate(trace: string, fetchedURL: string) {
|
|||
}
|
||||
z-index: 101;
|
||||
}
|
||||
|
||||
#errorTrace-wrapper {
|
||||
position: relative;
|
||||
width: fit-content;
|
||||
}
|
||||
|
||||
#copy-button {
|
||||
position: absolute;
|
||||
top: 0.5em;
|
||||
right: 0.5em;
|
||||
padding: 0.23em;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
transition: opacity 0.4s;
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
#errorTrace-wrapper:hover #copy-button {
|
||||
opacity: 1;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -117,8 +147,10 @@ export function errorTemplate(trace: string, fetchedURL: string) {
|
|||
<!-- <p id="errorMessage">Internal Server Error</p> -->
|
||||
|
||||
<div id="info">
|
||||
<textarea id="errorTrace" cols="40" rows="10" readonly>
|
||||
</textarea>
|
||||
<div id="errorTrace-wrapper">
|
||||
<textarea id="errorTrace" cols="40" rows="10" readonly></textarea>
|
||||
<button id="copy-button" class="primary">Copy</button>
|
||||
</div>
|
||||
<div id="troubleshooting">
|
||||
<p>Try:</p>
|
||||
<ul>
|
||||
|
|
|
@ -179,11 +179,29 @@ export async function swfetch(
|
|||
this
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("ERROR FROM SERVICE WORKER FETCH", err);
|
||||
const errorDetails = {
|
||||
message: err.message,
|
||||
url: request.url,
|
||||
destination: request.destination,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
if (err.stack) {
|
||||
errorDetails["stack"] = err.stack;
|
||||
}
|
||||
|
||||
console.error("ERROR FROM SERVICE WORKER FETCH: ", errorDetails);
|
||||
|
||||
if (!["document", "iframe"].includes(request.destination))
|
||||
return new Response(undefined, { status: 500 });
|
||||
|
||||
return renderError(err, unrewriteUrl(request.url));
|
||||
const formattedError = Object.entries(errorDetails)
|
||||
.map(
|
||||
([key, value]) =>
|
||||
`${key.charAt(0).toUpperCase() + key.slice(1)}: ${value}`
|
||||
)
|
||||
.join("\n\n");
|
||||
|
||||
return renderError(formattedError, unrewriteUrl(request.url));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue