feat: Add debug logging and enhance error messages for remote chat delivery failures.

This commit is contained in:
Christomatt
2026-01-29 11:17:26 +01:00
parent 1f115d569f
commit 705e7cd23f
+12 -4
View File
@@ -163,22 +163,30 @@ export async function POST(request: NextRequest) {
// 2. Send to Remote Node (Forward the Signed Action) // 2. Send to Remote Node (Forward the Signed Action)
try { try {
const protocol = targetDomain.includes('localhost') ? 'http' : 'https'; const protocol = targetDomain.includes('localhost') ? 'http' : 'https';
const sourceDomain = process.env.NEXT_PUBLIC_NODE_DOMAIN || '';
console.log(`[Remote Send] Debug:`, {
targetDomain,
targetUrl: `${protocol}://${targetDomain}/api/chat/receive`,
sourceDomainEnv: sourceDomain,
});
const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, { const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-Swarm-Source-Domain': process.env.NEXT_PUBLIC_NODE_DOMAIN || '' 'X-Swarm-Source-Domain': sourceDomain
}, },
body: JSON.stringify(signedAction) // Forward the user's signed intent body: JSON.stringify(signedAction) // Forward the user's signed intent
}); });
if (!res.ok) { if (!res.ok) {
const errText = await res.text(); const errText = await res.text();
console.error('Remote node rejected chat:', errText); console.error(`[Remote Send] Remote node rejected chat (${res.status}):`, errText);
return NextResponse.json({ error: `Remote delivery failed: ${res.statusText}` }, { status: 502 }); return NextResponse.json({ error: `Remote delivery failed: ${res.statusText} - ${errText}` }, { status: 502 });
} }
} catch (err: any) { } catch (err: any) {
console.error('Failed to contact remote node:', err); console.error('[Remote Send] Failed to contact remote node:', err);
return NextResponse.json({ error: 'Failed to contact remote node' }, { status: 504 }); return NextResponse.json({ error: 'Failed to contact remote node' }, { status: 504 });
} }