P
Prisma•6mo ago
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 }
);
}
}
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;
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
No description
1 Reply
RaphaelEtim
RaphaelEtim•6mo ago
Hi @gaurav1998 👋 Can you modify the catch block to log the actual error? This will provide more insight into what is going wrong. Once the error is logged, you can share it here.
catch (error) {
console.error("Error fetching service metadata:", error);
return NextResponse.json(
{ message: "Database Error: Failed to fetch service metadata.", error: error.message },
{ status: 500 }
);
}
catch (error) {
console.error("Error fetching service metadata:", error);
return NextResponse.json(
{ message: "Database Error: Failed to fetch service metadata.", error: error.message },
{ status: 500 }
);
}
Want results from more Discord servers?
Add your server