Skip to content

Commit 62d7bd5

Browse files
committed
Add timeout and debug logging to guilds API endpoint
1 parent d2e7916 commit 62d7bd5

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

dash/src/pages/api/guilds.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export default async function handler(
1313
return res.status(401).json({ error: 'Unauthorized' })
1414
}
1515

16+
console.log(`[DEBUG] BOT_API_URL: ${BOT_API_URL}`)
17+
1618
try {
1719
// Fetch user's guilds from Discord API
1820
const discordResponse = await fetch('https://discord.com/api/users/@me/guilds', {
@@ -38,7 +40,15 @@ export default async function handler(
3840
adminGuilds.map(async (guild: any) => {
3941
let hasMiku = false
4042
try {
41-
const botResponse = await fetch(`${BOT_API_URL}/api/guild/${guild.id}/has-bot`)
43+
// Add timeout to prevent hanging
44+
const controller = new AbortController()
45+
const timeoutId = setTimeout(() => controller.abort(), 5000) // 5 second timeout
46+
47+
const botResponse = await fetch(`${BOT_API_URL}/api/guild/${guild.id}/has-bot`, {
48+
signal: controller.signal
49+
})
50+
clearTimeout(timeoutId)
51+
4252
if (botResponse.ok) {
4353
const data = await botResponse.json()
4454
hasMiku = data.hasMiku

0 commit comments

Comments
 (0)