English 中文(简体)
POST要求返回 500 内部服务器
原标题:POST request returning 500 Internal Server Error Next.js

我正试图在我的下台上写一份简单的《名册》请求书。 我写了一份GET申请,并做了罚款。

Here is my basic code.

import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
  const body = await request.json();
  return NextResponse.json(body);
};

Here is the error in my terminal: ⨯ SyntaxError: Unexpected non-whitespace character after JSON at position 31 at JSON.parse () at parseJSONFromBytes (node:internal/deps/undici/undici:5329:19) at successSteps (node:internal/deps/undici/undici:5300:27) at fullyReadBody (node:internal/deps/undici/undici:1447:9) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async specConsumeBody (node:internal/deps/undici/undici:5309:7) at async POST (webpack-internal:///(rsc)/./app/api/projects/route.ts:11:18) at async /Users/austinwilliams/Desktop/portfolio-react/node_modules/next/dist/compiled/next-server/app-route.runtime.dev.js:6:63251

我试图去除 as子并等待,这将消除错误,但反应只是空话。 不能确定如何打断它是一种许诺,其职能需要作为整体。

When I remove the async await I get status 200 with an empty response object. enter image description here

问题回答

引证。

import { NextRequest, NextResponse } from "next/server";

export async function POST(request: NextRequest) {
  const body = request.body;
  return NextResponse.json(body);
}

我的JSON在邮官的物体有一 error子错误。





相关问题
Separating Business Layer Errors from API errors

The title is horrible, i know; I m terrible at titles on SO here. I m wondering what would be the best way to present unified error responses in a webapi when errors could be raised deep inside the ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

How to tell why a file deletion fails in Java?

File file = new File(path); if (!file.delete()) { throw new IOException( "Failed to delete the file because: " + getReasonForFileDeletionFailureInPlainEnglish(file)); } Is there a ...

Exceptions: redirect or render?

I m trying to standardize the way I handle exceptions in my web application (homemade framework) but I m not certain of the "correct" way to handle various situations. I m wondering if there is a ...

热门标签