refactor: Improve error handling for Discord API response parsing
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user