mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 13:24:27 +00:00
Add detailed logging to API endpoints for debugging 500 errors
This commit is contained in:
@@ -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 }
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user