From b812b8b17b70d7d049fa313c923ef3282d989aa3 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 17 Apr 2025 14:57:16 +1200 Subject: [PATCH] Some errors should be displayed to the user --- routes/load-collection.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/load-collection.js b/routes/load-collection.js index 5943cc3..54d50f6 100644 --- a/routes/load-collection.js +++ b/routes/load-collection.js @@ -15,13 +15,15 @@ const loadTags = sync.require("./load-tags") /** @type {import("./schema")} */ const schema = sync.require("./schema") +class UserVisibleError extends Error {} + async function loadCollection(inputUsername) { assert.match(inputUsername, /^[a-z0-9_-]+$/) const html = await fetch(`https://bandcamp.com/${inputUsername}`).then(res => res.text()) 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.") + if (!first) throw new UserVisibleError("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) @@ -110,7 +112,8 @@ router.post("/api/load-collection", defineEventHandler(async event => { setCookie(event, "accounts", (getCookie(event, "accounts") || "").split("|").concat(account).join("|")) return pugSync.render(event, "collection-loaded.pug", result) } catch (cause) { - const error = new class extends Error { + const error = cause instanceof UserVisibleError ? cause + : new class extends Error { name = "Collection Import Error" account = account cause = cause