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) {
const errorBody = await discordRes.json();
console.error('Discord API Error:', errorBody);
return NextResponse.json({ error: 'Failed to upload to Discord' }, { status: 500 });
let discordData;
try {
discordData = await discordRes.json();
} 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];
if (!attachment) {