I am trying to use the NextResponse from next/server. I am getting a status 500 and internal server error when i call the api. The condition.
if (response.status === 202)
is true and is able to enter the if block.
export async function POST(request: NextRequest) {
let body = await request.json();
console.log(body);
if (process.env.URL_FILE_SERVICE_CREATE_CATEGORY) {
axios.post(process.env.URL_FILE_SERVICE_CREATE_CATEGORY)
.then(response => {
if (response.status === 202) {
return NextResponse.json({ hello: 'Next.js' })
}
})
.catch(err => {
if (err.response.status === 409) {
return NextResponse.json({ message: "conflict" }, { status: 409 });
} else {
return NextResponse.json({ message: "Error" }, { status: 500 });
}
});
}
}