--- // Locale-basierte Produktseite import Layout from "../../../layouts/Layout.astro"; import Product from "../../../components/Product.astro"; import { getProducts } from "../../../lib/graphql/queries.js"; import { i18n } from "../../../lib/i18n/i18n.js"; import type { Product as ProductType } from "../../../lib/types/product.js"; const locale = Astro.params["locale"] || "de"; i18n.setLocale(locale); let products: ProductType[] = []; try { products = await getProducts(4); } catch (error) { // Verbindungsfehler weniger störend behandeln const isConnectionError = error instanceof Error && (error.name === "ConnectionError" || error.message.includes("GraphQL-Server nicht erreichbar") || error.message.includes("ECONNREFUSED")); if (isConnectionError) { // In Development: Warnung ausgeben if (import.meta.env.DEV) { console.warn( "GraphQL-Server nicht erreichbar. Verwende leere Produktliste." ); console.warn("Starte den Server mit: npm run mock:server"); } } else { console.error("Fehler beim Laden der Produkte:", error); } products = []; } const title = locale === "en" ? "Products" : "Produkte"; ---

{locale === "en" ? "Products" : "Produkte"}

{ products.length === 0 ? (

{locale === "en" ? "No products available. Make sure the GraphQL server is running." : "Keine Produkte verfügbar. Stelle sicher, dass der GraphQL-Server läuft."}

) : (
{products.map((product) => ( ))}
) }