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
This commit is contained in:
pac7
2025-10-08 12:53:14 +00:00
parent 3606e2ab54
commit 2b1dcd70ef

View File

@@ -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
}
);
}