debug: add comprehensive logging to deactivate-player endpoint
Add logging to both client and server side to debug 404 issue: Client side (useRoomData): - Log URL being called - Log params being sent - Log response status Server side (route): - Log when POST is received - Log roomId and viewerId - Log request body - Log member validation steps - Log success/error responses This will help identify why the endpoint is returning 404.
This commit is contained in:
@@ -15,19 +15,31 @@ type RouteContext = {
|
||||
* - playerId: string - The player to deactivate
|
||||
*/
|
||||
export async function POST(req: NextRequest, context: RouteContext) {
|
||||
console.log('[Deactivate Player API] POST request received')
|
||||
|
||||
try {
|
||||
const { roomId } = await context.params
|
||||
console.log('[Deactivate Player API] roomId:', roomId)
|
||||
|
||||
const viewerId = await getViewerId()
|
||||
console.log('[Deactivate Player API] viewerId:', viewerId)
|
||||
|
||||
const body = await req.json()
|
||||
console.log('[Deactivate Player API] body:', body)
|
||||
|
||||
// Validate required fields
|
||||
if (!body.playerId) {
|
||||
console.log('[Deactivate Player API] Missing playerId in body')
|
||||
return NextResponse.json({ error: 'Missing required field: playerId' }, { status: 400 })
|
||||
}
|
||||
|
||||
// Check if user is the host
|
||||
console.log('[Deactivate Player API] Fetching room members for roomId:', roomId)
|
||||
const members = await getRoomMembers(roomId)
|
||||
console.log('[Deactivate Player API] members count:', members.length)
|
||||
|
||||
const currentMember = members.find((m) => m.userId === viewerId)
|
||||
console.log('[Deactivate Player API] currentMember:', currentMember)
|
||||
|
||||
if (!currentMember) {
|
||||
return NextResponse.json({ error: 'You are not in this room' }, { status: 403 })
|
||||
@@ -93,9 +105,11 @@ export async function POST(req: NextRequest, context: RouteContext) {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[Deactivate Player API] Success - returning 200')
|
||||
return NextResponse.json({ success: true }, { status: 200 })
|
||||
} catch (error: any) {
|
||||
console.error('Failed to deactivate player:', error)
|
||||
console.error('[Deactivate Player API] ERROR:', error)
|
||||
console.error('[Deactivate Player API] Error stack:', error.stack)
|
||||
return NextResponse.json({ error: 'Failed to deactivate player' }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,16 +796,27 @@ async function deactivatePlayerInRoomApi(params: {
|
||||
roomId: string
|
||||
playerId: string
|
||||
}): Promise<void> {
|
||||
const response = await fetch(`/api/arcade/rooms/${params.roomId}/deactivate-player`, {
|
||||
const url = `/api/arcade/rooms/${params.roomId}/deactivate-player`
|
||||
console.log('[useRoomData] deactivatePlayerInRoomApi called')
|
||||
console.log('[useRoomData] URL:', url)
|
||||
console.log('[useRoomData] params:', params)
|
||||
|
||||
const response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ playerId: params.playerId }),
|
||||
})
|
||||
|
||||
console.log('[useRoomData] Response status:', response.status)
|
||||
console.log('[useRoomData] Response ok:', response.ok)
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json()
|
||||
console.error('[useRoomData] Error response:', errorData)
|
||||
throw new Error(errorData.error || 'Failed to deactivate player')
|
||||
}
|
||||
|
||||
console.log('[useRoomData] deactivatePlayerInRoomApi success')
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user