🚀 report error in demo

This commit is contained in:
platane
2020-10-24 00:15:47 +02:00
parent 43aa3022af
commit 64b04e9eba
2 changed files with 11 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ export const getBestRoute = (grid0: Grid, snake0: Snake) => {
const chunk = pruneLayer(grid, color, snakeN);
const c = cleanLayer(gridN, chain[0], chunk);
if (c) chain.unshift(...c);
else throw new Error("some cells are unreachable");
}
return chain.reverse().slice(1);

View File

@@ -12,7 +12,11 @@ import {
import { userContributionToGrid } from "../action/userContributionToGrid";
import { snake3 } from "@snk/types/__fixtures__/snake";
const createForm = ({ onSubmit }: { onSubmit: (s: string) => void }) => {
const createForm = ({
onSubmit,
}: {
onSubmit: (s: string) => Promise<void>;
}) => {
const form = document.createElement("form");
form.style.position = "relative";
form.style.display = "flex";
@@ -26,7 +30,6 @@ const createForm = ({ onSubmit }: { onSubmit: (s: string) => void }) => {
submit.innerText = "ok";
const label = document.createElement("label");
label.innerText = "loading ...";
label.style.position = "absolute";
label.style.textAlign = "center";
label.style.top = "60px";
@@ -61,11 +64,15 @@ const createForm = ({ onSubmit }: { onSubmit: (s: string) => void }) => {
const u = new URLSearchParams(window.location.search).get("userName");
if (u) {
input.value = u;
onSubmit(u);
onSubmit(u).catch((err) => {
label.innerText = "error :(";
throw err;
});
input.disabled = true;
submit.disabled = true;
form.appendChild(label);
label.innerText = "loading ...";
}
return { dispose };