From 01dc9233edf40a74a1ef341415c25d0f6d73bf95 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Sat, 2 Aug 2025 09:58:28 -0500 Subject: [PATCH] Remove unnecessary `throw` commands --- src/lib/utils/websocket_utils.ts | 16 ++++++++-------- src/routes/publication/+page.server.ts | 10 +++++----- .../[type]/[identifier]/+layout.server.ts | 2 +- .../publication/[type]/[identifier]/+layout.ts | 4 ++-- .../[type]/[identifier]/+page.server.ts | 2 +- .../publication/[type]/[identifier]/+page.ts | 6 +++--- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/lib/utils/websocket_utils.ts b/src/lib/utils/websocket_utils.ts index bad0818..f43f908 100644 --- a/src/lib/utils/websocket_utils.ts +++ b/src/lib/utils/websocket_utils.ts @@ -70,14 +70,14 @@ export async function fetchEventById(id: string): Promise { try { const event = await fetchNostrEvent({ ids: [id], limit: 1 }); if (!event) { - throw error(404, `Event not found for ID: ${id}`); + error(404, `Event not found for ID: ${id}`); } return event; } catch (err) { if (err && typeof err === "object" && "status" in err) { throw err; } - throw error(404, `Failed to fetch event by ID: ${err}`); + error(404, `Failed to fetch event by ID: ${err}`); } } @@ -88,14 +88,14 @@ export async function fetchEventByDTag(dTag: string): Promise { try { const event = await fetchNostrEvent({ "#d": [dTag], limit: 1 }); if (!event) { - throw error(404, `Event not found for d-tag: ${dTag}`); + error(404, `Event not found for d-tag: ${dTag}`); } return event; } catch (err) { if (err && typeof err === "object" && "status" in err) { throw err; } - throw error(404, `Failed to fetch event by d-tag: ${err}`); + error(404, `Failed to fetch event by d-tag: ${err}`); } } @@ -112,14 +112,14 @@ export async function fetchEventByNaddr(naddr: string): Promise { }; const event = await fetchNostrEvent(filter); if (!event) { - throw error(404, `Event not found for naddr: ${naddr}`); + error(404, `Event not found for naddr: ${naddr}`); } return event; } catch (err) { if (err && typeof err === "object" && "status" in err) { throw err; } - throw error(404, `Failed to fetch event by naddr: ${err}`); + error(404, `Failed to fetch event by naddr: ${err}`); } } @@ -131,13 +131,13 @@ export async function fetchEventByNevent(nevent: string): Promise { const decoded = neventDecode(nevent); const event = await fetchNostrEvent({ ids: [decoded.id], limit: 1 }); if (!event) { - throw error(404, `Event not found for nevent: ${nevent}`); + error(404, `Event not found for nevent: ${nevent}`); } return event; } catch (err) { if (err && typeof err === "object" && "status" in err) { throw err; } - throw error(404, `Failed to fetch event by nevent: ${err}`); + error(404, `Failed to fetch event by nevent: ${err}`); } } diff --git a/src/routes/publication/+page.server.ts b/src/routes/publication/+page.server.ts index 1b66af2..fa30a0d 100644 --- a/src/routes/publication/+page.server.ts +++ b/src/routes/publication/+page.server.ts @@ -25,17 +25,17 @@ export const load: PageServerLoad = ({ url }) => { if (id) { // Check if id is an naddr or nevent if (id.startsWith(IDENTIFIER_PREFIXES.NADDR)) { - throw redirect(301, `${ROUTES.NADDR}/${id}`); + redirect(301, `${ROUTES.NADDR}/${id}`); } else if (id.startsWith(IDENTIFIER_PREFIXES.NEVENT)) { - throw redirect(301, `${ROUTES.NEVENT}/${id}`); + redirect(301, `${ROUTES.NEVENT}/${id}`); } else { // Assume it's a hex ID - throw redirect(301, `${ROUTES.ID}/${id}`); + redirect(301, `${ROUTES.ID}/${id}`); } } else if (dTag) { - throw redirect(301, `${ROUTES.D_TAG}/${dTag}`); + redirect(301, `${ROUTES.D_TAG}/${dTag}`); } // If no query parameters, redirect to the start page - throw redirect(301, ROUTES.START); + redirect(301, ROUTES.START); }; \ No newline at end of file diff --git a/src/routes/publication/[type]/[identifier]/+layout.server.ts b/src/routes/publication/[type]/[identifier]/+layout.server.ts index f97639a..31e9c54 100644 --- a/src/routes/publication/[type]/[identifier]/+layout.server.ts +++ b/src/routes/publication/[type]/[identifier]/+layout.server.ts @@ -7,7 +7,7 @@ export const load: LayoutServerLoad = async ({ params, url }) => { // Validate the identifier type for SSR const validTypes = ['id', 'd', 'naddr', 'nevent']; if (!validTypes.includes(type)) { - throw error(400, `Unsupported identifier type: ${type}`); + error(400, `Unsupported identifier type: ${type}`); } // Provide basic metadata for SSR - actual fetching will happen on client diff --git a/src/routes/publication/[type]/[identifier]/+layout.ts b/src/routes/publication/[type]/[identifier]/+layout.ts index 0830e1a..d181095 100644 --- a/src/routes/publication/[type]/[identifier]/+layout.ts +++ b/src/routes/publication/[type]/[identifier]/+layout.ts @@ -39,7 +39,7 @@ export const load: LayoutLoad = async ({ params, url }) => { indexEvent = await fetchEventByNevent(identifier); break; default: - throw error(400, `Unsupported identifier type: ${type}`); + error(400, `Unsupported identifier type: ${type}`); } // Extract metadata for meta tags @@ -60,6 +60,6 @@ export const load: LayoutLoad = async ({ params, url }) => { }; } catch (err) { console.error('Failed to fetch publication:', err); - throw error(404, `Failed to load publication: ${err}`); + error(404, `Failed to load publication: ${err}`); } }; diff --git a/src/routes/publication/[type]/[identifier]/+page.server.ts b/src/routes/publication/[type]/[identifier]/+page.server.ts index 5695e77..eeffa46 100644 --- a/src/routes/publication/[type]/[identifier]/+page.server.ts +++ b/src/routes/publication/[type]/[identifier]/+page.server.ts @@ -7,7 +7,7 @@ export const load: PageServerLoad = async ({ params }) => { // Validate the identifier type for SSR const validTypes = ['id', 'd', 'naddr', 'nevent']; if (!validTypes.includes(type)) { - throw error(400, `Unsupported identifier type: ${type}`); + error(400, `Unsupported identifier type: ${type}`); } // Provide basic data for SSR - actual fetching will happen on client diff --git a/src/routes/publication/[type]/[identifier]/+page.ts b/src/routes/publication/[type]/[identifier]/+page.ts index 6de9d27..5d2d444 100644 --- a/src/routes/publication/[type]/[identifier]/+page.ts +++ b/src/routes/publication/[type]/[identifier]/+page.ts @@ -34,11 +34,11 @@ export const load: PageLoad = async ({ params }) => { indexEvent = await fetchEventByNevent(identifier); break; default: - throw error(400, `Unsupported identifier type: ${type}`); + error(400, `Unsupported identifier type: ${type}`); } if (!indexEvent) { - throw error(404, `Event not found for ${type}: ${identifier}`); + error(404, `Event not found for ${type}: ${identifier}`); } const publicationType = indexEvent.tags.find((tag) => tag[0] === "type")?.[1] ?? ""; @@ -49,6 +49,6 @@ export const load: PageLoad = async ({ params }) => { }; } catch (err) { console.error('Failed to fetch publication:', err); - throw error(404, `Failed to load publication: ${err}`); + error(404, `Failed to load publication: ${err}`); } }; \ No newline at end of file