Show notices for server errors

This commit is contained in:
Cadence Ember 2025-04-10 15:07:39 +12:00
parent 62e7ccf17b
commit b1ab998a4b
4 changed files with 38 additions and 9 deletions

View file

@ -21,6 +21,7 @@ async function loadCollection(inputUsername) {
const doc = domino.createDocument(html)
const first = doc.querySelector(".collection-item-container[data-token]")
if (!first) throw new Error("Account does not exist. Please check the username - it's easy to mix it up with the display name, which is different.")
assert(first)
const token = first.getAttribute("data-token")
assert(token)
@ -94,7 +95,11 @@ async function loadCollection(inputUsername) {
router.post("/api/load-collection", defineEventHandler(async event => {
const {account} = await readValidatedBody(event, schema.schema.account.parse)
const result = await loadCollection(account)
setCookie(event, "accounts", (getCookie(event, "accounts") || "").split("|").concat(account).join("|"))
return pugSync.render(event, "collection-loaded.pug", result)
try {
const result = await loadCollection(account)
setCookie(event, "accounts", (getCookie(event, "accounts") || "").split("|").concat(account).join("|"))
return pugSync.render(event, "collection-loaded.pug", result)
} catch (error) {
return pugSync.render(event, "collection-loaded.pug", {error})
}
}))