hoangvvo / next-connect

The TypeScript-ready, minimal router and middleware layer for Next.js, Micro, Vercel, or Node.js http/http2
https://www.npmjs.com/package/next-connect
MIT License
1.64k stars 65 forks source link

Prisma Ensure you return a `Response` or a `NextResponse` in all branches of your handler #238

Open FelipeFardo opened 11 months ago

FelipeFardo commented 11 months ago

The client receives a 500 response even though the code execution has not finished.

GET `routerGET.get(async (req, res) => { try { const storeId = res.params.storeId; const { searchParams } = new URL(req.url);

const categoryId = searchParams.get('categoryId') || undefined;
const colorId = searchParams.get('colorId') || undefined;
const sizeId = searchParams.get('sizeId') || undefined;
const isFeatured = searchParams.get('isFeatured');

const products = await prismadb.product.findMany({
  where: {
    storeId,
    categoryId,
    colorId,
    sizeId,
    isFeatured: isFeatured ? true : undefined,
    isArchived: false,
  },
  include: {
    images: true,
    category: true,
    color: true,
    size: true,
  },
  orderBy: {
    createdAt: 'desc',
  }
});

const response = FormateResponse.success({
  message: 'Products',
  data: { products }
});
return NextResponse.json(JSON.stringify(response), { status: response.statusCode });

} catch (error) { console.log('[PRODUCTS_GET]', error); return new NextResponse("Internal error", { status: 500 }); } // Adicione um retorno no final da função, caso nenhum dos retornos anteriores seja alcançado. return new NextResponse("Internal error", { status: 500 }); })`

image

image

image