mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-28 14:34:18 +03:00
Handle initial content.json errors with hot reloading.
This commit is contained in:
parent
0e8f48bb72
commit
a2d17c26c8
@ -219,8 +219,13 @@ async function start(options) {
|
||||
}
|
||||
} catch (error) {
|
||||
console.log({ error });
|
||||
res.writeHead(500, { "Content-Type": "text/html" });
|
||||
res.end(errorHtml());
|
||||
if (req.url.includes("content.json")) {
|
||||
res.writeHead(500, { "Content-Type": "application/json" });
|
||||
res.end(JSON.stringify(error.errorsJson));
|
||||
} else {
|
||||
res.writeHead(500, { "Content-Type": "text/html" });
|
||||
res.end(errorHtml());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,35 +9,39 @@ function connect(sendContentJsonPort, initialErrorPage) {
|
||||
eventSource = new EventSource("/stream");
|
||||
window.reloadOnOk = initialErrorPage;
|
||||
if (initialErrorPage) {
|
||||
elmJsFetch().then(thenApplyHmr);
|
||||
handleEvent(sendContentJsonPort, { data: "content.json" });
|
||||
}
|
||||
eventSource.onmessage = async function (evt) {
|
||||
showCompiling("");
|
||||
if (evt.data === "content.json") {
|
||||
const elmJsRequest = elmJsFetch();
|
||||
const fetchContentJson = fetchContentJsonForCurrentPage();
|
||||
updateAppContentJson = updateContentJsonWith(
|
||||
fetchContentJson,
|
||||
sendContentJsonPort
|
||||
);
|
||||
|
||||
try {
|
||||
await fetchContentJson;
|
||||
const elmJsResponse = await elmJsRequest;
|
||||
thenApplyHmr(elmJsResponse);
|
||||
} catch (errorJson) {
|
||||
console.log({ errorJson });
|
||||
showError({
|
||||
type: "compile-errors",
|
||||
errors: errorJson,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
elmJsFetch().then(thenApplyHmr);
|
||||
}
|
||||
handleEvent(sendContentJsonPort, evt);
|
||||
};
|
||||
}
|
||||
|
||||
async function handleEvent(sendContentJsonPort, evt) {
|
||||
showCompiling("");
|
||||
if (evt.data === "content.json") {
|
||||
const elmJsRequest = elmJsFetch();
|
||||
const fetchContentJson = fetchContentJsonForCurrentPage();
|
||||
updateAppContentJson = updateContentJsonWith(
|
||||
fetchContentJson,
|
||||
sendContentJsonPort
|
||||
);
|
||||
|
||||
try {
|
||||
await fetchContentJson;
|
||||
const elmJsResponse = await elmJsRequest;
|
||||
thenApplyHmr(elmJsResponse);
|
||||
} catch (errorJson) {
|
||||
console.log({ errorJson });
|
||||
showError({
|
||||
type: "compile-errors",
|
||||
errors: errorJson,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
elmJsFetch().then(thenApplyHmr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} fetchContentJsonPromise
|
||||
|
Loading…
Reference in New Issue
Block a user