Add detailed logging to API endpoints for debugging 500 errors

This commit is contained in:
Marco Gallegos
2026-01-18 08:49:16 -06:00
parent c0a9568e5c
commit 93366fc596
17 changed files with 2020 additions and 127 deletions

View File

@@ -6,28 +6,52 @@ import { supabase } from '@/lib/supabase/client'
*/
export async function GET(request: NextRequest) {
try {
const { data: locations, error } = await supabase
console.log('Locations API called with URL:', request.url)
// Check Supabase connection
console.log('Supabase URL:', process.env.NEXT_PUBLIC_SUPABASE_URL)
console.log('Supabase key exists:', !!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)
console.log('Executing locations query...')
const { data: locationsData, error: queryError } = await supabase
.from('locations')
.select('*')
.eq('is_active', true)
.order('name', { ascending: true })
if (error) {
console.error('Locations GET error:', error)
console.log('Query result - data:', !!locationsData, 'error:', !!queryError)
if (queryError) {
console.error('Locations GET error details:', {
message: queryError.message,
code: queryError.code,
details: queryError.details,
hint: queryError.hint
})
return NextResponse.json(
{ error: error.message },
{
error: queryError.message,
code: queryError.code,
details: queryError.details
},
{ status: 500 }
)
}
console.log('Locations found:', locationsData?.length || 0)
return NextResponse.json({
success: true,
locations: locations || []
locations: locationsData || [],
count: locationsData?.length || 0
})
} catch (error) {
console.error('Locations GET error:', error)
console.error('Locations GET unexpected error:', error)
console.error('Error stack:', error instanceof Error ? error.stack : 'Unknown error')
return NextResponse.json(
{ error: 'Internal server error' },
{
error: 'Internal server error',
details: error instanceof Error ? error.message : 'Unknown error'
},
{ status: 500 }
)
}