You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there, I have faced an error while creating a project. This is a file in the route.js. I am using prisma database to connect. I have checked all those npx prisma migrate and they still came out with this error.
Here is my code:
`import db from "@/lib/db";
import { NextResponse } from "next/server";
export async function POST(request) {
try {
// Read and parse request body
let body;
try {
body = await request.json();
} catch (err) {
console.error("Invalid JSON received:", err);
return NextResponse.json(
{ message: "Invalid JSON format" },
{ status: 400 }
);
}
Hi there, I have faced an error while creating a project. This is a file in the route.js. I am using prisma database to connect. I have checked all those npx prisma migrate and they still came out with this error.
Here is my code:
`import db from "@/lib/db";
import { NextResponse } from "next/server";
export async function POST(request) {
try {
// Read and parse request body
let body;
try {
body = await request.json();
} catch (err) {
console.error("Invalid JSON received:", err);
return NextResponse.json(
{ message: "Invalid JSON format" },
{ status: 400 }
);
}
} catch (error) {
console.error("Error creating item:", error);
return NextResponse.json(
{ message: "Failed to create item", error: error.message },
{ status: 500 }
);
}
}
export async function GET(request) {
try {
const items = await db.item.findMany({
orderBy: { createdAt: "desc" },
});
return NextResponse.json(items);
} catch (error) {
console.error("Error fetching items:", error);
return NextResponse.json(
{ message: "Failed to fetch items", error: error.message },
{ status: 400 }
);
}
}
`Please help me ASAP. Thank you everyone!
The text was updated successfully, but these errors were encountered: