From a30933cae8392ec0e5dc68d634cb332c56d95654 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 8 Nov 2025 21:06:33 +0000 Subject: [PATCH] completionId: cgen-5828f4bc911640c7ab9888129e0d788e cgen-5828f4bc911640c7ab9888129e0d788e --- api/discord/role-mappings.ts | 37 +++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/api/discord/role-mappings.ts b/api/discord/role-mappings.ts index 56a993f6..c5ec8b53 100644 --- a/api/discord/role-mappings.ts +++ b/api/discord/role-mappings.ts @@ -44,21 +44,36 @@ export default async function handler( } try { + // Validate Supabase is initialized + if (!supabase) { + console.error("Supabase client not initialized"); + return res.status(500).json({ + error: "Server configuration error: Missing Supabase credentials", + }); + } + // GET - Fetch all role mappings if (req.method === "GET") { - const { data, error } = await supabase - .from("discord_role_mappings") - .select("*") - .order("created_at", { ascending: false }); + try { + const { data, error } = await supabase + .from("discord_role_mappings") + .select("*") + .order("created_at", { ascending: false }); - if (error) { - console.error("Supabase error:", error); - return res - .status(500) - .json({ error: "Failed to fetch role mappings" }); + if (error) { + console.error("Supabase error:", error); + return res.status(500).json({ + error: `Failed to fetch role mappings: ${error.message}`, + }); + } + + return res.status(200).json(data || []); + } catch (queryErr: any) { + console.error("Query error:", queryErr); + return res.status(500).json({ + error: `Database query error: ${queryErr?.message || "Unknown error"}`, + }); } - - return res.status(200).json(data || []); } // POST - Create new role mapping