From 4db1f0b09eebb00a3fcf231eedb6baba5db7782e Mon Sep 17 00:00:00 2001 From: Nulo Date: Sat, 14 Sep 2024 20:36:08 -0300 Subject: [PATCH] mejores errores --- sepa/sitio2/src/routes/+error.svelte | 26 +++++++++++++++++++ .../routes/id_producto/[id]/+page.server.ts | 5 ++++ 2 files changed, 31 insertions(+) create mode 100644 sepa/sitio2/src/routes/+error.svelte diff --git a/sepa/sitio2/src/routes/+error.svelte b/sepa/sitio2/src/routes/+error.svelte new file mode 100644 index 0000000..6570241 --- /dev/null +++ b/sepa/sitio2/src/routes/+error.svelte @@ -0,0 +1,26 @@ + + +
+

Error {$page.status} :(

+

{$page.error?.message}

+ +
+ + +
+
diff --git a/sepa/sitio2/src/routes/id_producto/[id]/+page.server.ts b/sepa/sitio2/src/routes/id_producto/[id]/+page.server.ts index e08e8d9..12e9ca9 100644 --- a/sepa/sitio2/src/routes/id_producto/[id]/+page.server.ts +++ b/sepa/sitio2/src/routes/id_producto/[id]/+page.server.ts @@ -2,6 +2,7 @@ import { db } from '$lib/server/db'; import type { PageServerLoad } from './$types'; import { datasets, precios, sucursales } from '$lib/server/db/schema'; import { and, eq, sql } from 'drizzle-orm'; +import { error } from '@sveltejs/kit'; export const load: PageServerLoad = async ({ params, setHeaders }) => { const id = BigInt(params.id); const preciosRes = await db @@ -51,6 +52,10 @@ ORDER BY d1.id_comercio) 'Cache-Control': 'public, max-age=600' }); + if (preciosRes.length == 0) { + return error(404, `Producto ${params.id} no encontrado`); + } + // const precios = await sql< // { // productos_precio_lista: number;