refactor: Improve error handling for Discord API response parsing

This commit is contained in:
2025-10-16 13:33:35 +02:00
parent 968a843120
commit 49a6131b23

View File

@@ -33,13 +33,18 @@ export async function POST(request: Request) {
} }
); );
if (!discordRes.ok) { let discordData;
const errorBody = await discordRes.json(); try {
console.error('Discord API Error:', errorBody); discordData = await discordRes.json();
return NextResponse.json({ error: 'Failed to upload to Discord' }, { status: 500 }); } catch (jsonError) {
console.error('Failed to parse Discord response as JSON:', jsonError);
return NextResponse.json({ error: 'Failed to parse Discord response' }, { status: 500 });
} }
const discordData = await discordRes.json(); if (!discordRes.ok) {
console.error('Discord API Error:', discordData);
return NextResponse.json({ error: 'Failed to upload to Discord' }, { status: 500 });
}
const attachment = discordData.attachments[0]; const attachment = discordData.attachments[0];
if (!attachment) { if (!attachment) {