fix: wrap mii classes in try/catch in submit route

This commit is contained in:
trafficlunar 2025-04-05 17:16:41 +01:00
parent 37af539911
commit c2e74c89bb

View file

@ -60,15 +60,23 @@ export async function POST(request: Request) {
return Response.json({ error: "QR code is not a valid Mii QR code" }, { status: 400 }); return Response.json({ error: "QR code is not a valid Mii QR code" }, { status: 400 });
// Convert to Mii class // Convert to Mii class
let mii: Mii;
let tomodachiLifeMii: TomodachiLifeMii;
try {
const buffer = Buffer.from(result); const buffer = Buffer.from(result);
const mii = new Mii(buffer); mii = new Mii(buffer);
const tomodachiLifeMii = TomodachiLifeMii.fromBytes(qrBytes); tomodachiLifeMii = TomodachiLifeMii.fromBytes(qrBytes);
if (tomodachiLifeMii.hairDyeEnabled) { if (tomodachiLifeMii.hairDyeEnabled) {
mii.hairColor = tomodachiLifeMii.studioHairColor; mii.hairColor = tomodachiLifeMii.studioHairColor;
mii.eyebrowColor = tomodachiLifeMii.studioHairColor; mii.eyebrowColor = tomodachiLifeMii.studioHairColor;
mii.facialHairColor = tomodachiLifeMii.studioHairColor; mii.facialHairColor = tomodachiLifeMii.studioHairColor;
} }
} catch (error) {
console.warn("Mii data is not valid:", error);
return Response.json({ error: "Mii data is not valid" }, { status: 400 });
}
// Create Mii in database // Create Mii in database
const miiRecord = await prisma.mii.create({ const miiRecord = await prisma.mii.create({