PrismaP
Prisma2y ago
2 replies
gaurav1998

500 (Internal Server Error) from simple query

I am running the following query:
import { unstable_noStore as noStore } from "next/cache";
import { NextResponse } from "next/server";
import { prisma } from "@/db/client";

export async function GET(request: Request) {
  noStore();

  try {
    console.log("Hello World1");
    const serviceMetaData = await prisma.service.findMany();

    console.log("Hello World2");
    return NextResponse.json(serviceMetaData);
  } catch (error) {
    return NextResponse.json(
      { message: "Database Error: Failed to fetch service metadata." },
      { status: 500 }
    );
  }
}

Where client.ts is:
import { PrismaClient } from "@prisma/client";

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };

export const prisma = globalForPrisma.prisma || new PrismaClient();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

And I have a populated Service table in my Supabase (see attached screenshot). I run npx prisma generate just to make sure my prisma instance is up to date but whenever I reload the page, which sends another get request, I get a 500 Internal Server Error.

Hello World1 will print while Hello World2 won't, so the issue has to do with querying the databse.

Any idea what the issue might be? Thank you for your guidance
Screenshot_2024-05-30_at_11.24.23_PM.png
Was this page helpful?