mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 06:11:12 -05:00
Improve location data handling and error reporting in the app
Update LocationSearch component to safely access address properties and add fallback values for city, state, and country. Refactor supabase/functions/detect-location/index.ts to use a generic endRequest function, removing hardcoded status codes for error handling. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 3c76e833-eccc-4712-b9a4-70241b5590a1 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -146,18 +146,23 @@ export function LocationSearch({ onLocationSelect, initialLocationId, className
|
||||
const latitude = parseFloat(result.lat);
|
||||
const longitude = parseFloat(result.lon);
|
||||
|
||||
const city = result.address.city || result.address.town || result.address.village;
|
||||
// Safely access address properties with fallback
|
||||
const address = result.address || {};
|
||||
const city = address.city || address.town || address.village;
|
||||
const state = address.state || '';
|
||||
const country = address.country || 'Unknown';
|
||||
|
||||
const locationName = city
|
||||
? `${city}, ${result.address.state || ''} ${result.address.country}`.trim()
|
||||
? `${city}, ${state} ${country}`.trim()
|
||||
: result.display_name;
|
||||
|
||||
// Build location data object (no database operations)
|
||||
const locationData: SelectedLocation = {
|
||||
name: locationName,
|
||||
city: city || undefined,
|
||||
state_province: result.address.state || undefined,
|
||||
country: result.address.country || '',
|
||||
postal_code: result.address.postcode || undefined,
|
||||
state_province: state || undefined,
|
||||
country: country,
|
||||
postal_code: address.postcode || undefined,
|
||||
latitude,
|
||||
longitude,
|
||||
timezone: undefined, // Will be set by server during approval if needed
|
||||
|
||||
Reference in New Issue
Block a user