Skip to content

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

@FelipeFardo

Description

@FelipeFardo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions