Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FelipeFardo opened this issue Nov 4, 2023 · 0 comments

Comments

@FelipeFardo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant