Getting 500 internal server error after trying to fetch and then post to vercel postgres databasse
Answered
Philippine Crocodile posted this in #help-forum
Philippine CrocodileOP
Code:
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
export async function POST(request) {
try {
const {
city,
country,
currentTemp,
currentWeather,
currentDate,
createdAt,
tomorrowMin,
tomorrowMax,
tomorrowWeather,
tomorrowDate,
} = await request.json();
console.log({
city,
country,
currentTemp,
currentWeather,
currentDate,
createdAt,
tomorrowMin,
tomorrowMax,
tomorrowWeather,
tomorrowDate,
});
const result = await prisma.WeatherCheck.create({
data: {
city,
country,
currentTemp,
currentWeather,
currentDate,
createdAt,
tomorrowMin,
tomorrowMax,
tomorrowWeather,
tomorrowDate,
},
});
return NextResponse.json({ data: result });
} catch (error) {
console.error("Error:", error);
return NextResponse.error("Internal Server Error");
}
}Answered by Philippine Crocodile
Ah thank you seems ike I have the wrong datatetype on one of my cells
21 Replies
Philippine CrocodileOP
above code is my route.js
```
is my app/add-fetch/page.jsx
is my app/add-fetch/page.jsx
Philippine CrocodileOP
errors im getting
Philippine CrocodileOP
is my app/add-fetch/page.jsx
@Ray do you see any errors logged on the server console
Philippine CrocodileOP
The 500 disappeared to a 405 instead but I’m still as confused 🫤
@Philippine Crocodile The 500 disappeared to a 405 instead but I’m still as confused 🫤
are you trying it on localhost or on vercel?
did you change anything?
@Ray are you trying it on localhost or on vercel?
Philippine CrocodileOP
Tried on both and nothing specially but the get succeeds it’s just the post
@Philippine Crocodile Tried on both and nothing specially but the get succeeds it’s just the post
try changing the function to this and test the endpoint with curl or something else
export async function POST() {
return new Response("POST")
}@Ray try changing the function to this and test the endpoint with curl or something else
ts
export async function POST() {
return new Response("POST")
}
Philippine CrocodileOP
My apologies I booted the vscode up and seems like I still have the 500 internal server error, pretty sure I did something thhat resulted in 405 instead but probably didn't save.
@Philippine Crocodile My apologies I booted the vscode up and seems like I still have the 500 internal server error, pretty sure I did something thhat resulted in 405 instead but probably didn't save.
do you see error in the server console? not the browser
@Ray do you see error in the server console? not the browser
Philippine CrocodileOP
Sorry, mind explaining how I can do that ?
do u mean the node?
@Philippine Crocodile do u mean the node?
yes, in the terminal where you run the app
the log from server will be printed on there
Philippine CrocodileOP
Ah thank you seems ike I have the wrong datatetype on one of my cells
Answer
@Philippine Crocodile Ah thank you seems ike I have the wrong datatetype on one of my cells
cool, now you know how to fix it
@Ray cool, now you know how to fix it
Philippine CrocodileOP
yeah I totally forgot checking server console I appreciate man!