From 2b1dcd70efaece35759d215e20b1cf4d8c0d16f4 Mon Sep 17 00:00:00 2001 From: pac7 <47831526-pac7@users.noreply.replit.com> Date: Wed, 8 Oct 2025 12:53:14 +0000 Subject: [PATCH] Improve error reporting for location detection to include status codes Update the detect-location Supabase function to return a 500 status code and an error message on failure, improving debugging and error monitoring. Replit-Commit-Author: Agent Replit-Commit-Session-Id: fe5b902e-beda-40fc-bf87-a3c4ab300e3a Replit-Commit-Checkpoint-Type: intermediate_checkpoint --- supabase/functions/detect-location/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/supabase/functions/detect-location/index.ts b/supabase/functions/detect-location/index.ts index 5acd45b0..c26fef0d 100644 --- a/supabase/functions/detect-location/index.ts +++ b/supabase/functions/detect-location/index.ts @@ -79,7 +79,8 @@ serve(async (req) => { } catch (error) { console.error('Error detecting location:', error); - // Return default (metric) on error + // Return default (metric) with 500 status to indicate error occurred + // This allows proper error monitoring while still providing fallback data const defaultResult: IPLocationResponse = { country: 'Unknown', countryCode: 'XX', @@ -87,13 +88,17 @@ serve(async (req) => { }; return new Response( - JSON.stringify(defaultResult), + JSON.stringify({ + ...defaultResult, + error: error instanceof Error ? error.message : 'Failed to detect location', + fallback: true + }), { headers: { ...corsHeaders, 'Content-Type': 'application/json' }, - status: 200 // Return 200 even on error to provide fallback + status: 500 } ); }