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) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user