#4467·blitz

[blitz-rpc] rpcAppHandler crashes on GET queries with SyntaxError (await req.json()) and reads non-existent route parameters instead of searchParams

Author: codeCraft-RitikCreated Sep 26, 2026Updated Sep 26, 2026
Labelskind/bugstatus/triage

What is the problem?

In Next.js App Router, any Blitz query configured with httpMethod = "GET" in its resolver config crashes unconditionally with SyntaxError: Unexpected end of JSON input.

In packages/blitz-rpc/src/index-server.ts, rpcAppHandler unconditionally executes:

typescript
const body = await req.json()

before verifying whether the HTTP method is POST. In WHATWG Fetch standard (Request), HTTP GET requests do not contain a body, so calling await req.json() throws a fatal SyntaxError.

Furthermore:

  1. rpcAppHandler attempts to read GET query arguments from params.params. But in App Router, segmentData.params only contains dynamic route segments ({ blitz: [...] }). URL search parameters (?params=...&meta=...) are on new URL(req.url).searchParams. Even if req.json() did not throw, GET queries receive undefined for all arguments.
  2. In the catch block of rpcAppHandler, new Response(...) fails to set status: error.statusCode || 500 and headers: { "Content-Type": "application/json" }. All server errors are returned as HTTP 200 with text/plain, misleading client error handlers.

Paste all your error logs here:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Response.json (node:internal/deps/undici/undici:5540:23)
    at handleRpcRequest (packages/blitz-rpc/src/index-server.ts:405:24)
    at async /node_modules/next/dist/server/future/route-modules/app-route/module.js:254:37

Paste all relevant code snippets here:

typescript
// packages/blitz-rpc/src/index-server.ts (lines 401-426)
if (
  req.method === "POST" ||
  (req.method === "GET" && resolverConfigWithDefaults.httpMethod === "GET")
) {
  // BUG: Executes on GET requests, throwing SyntaxError
  const body = await req.json()
  if (req.method === "POST" && typeof body.params === "undefined") {
    const error = {message: "Request body is missing the `params` key"}
    rpcLogger.error(error.message)
    return new Response(JSON.stringify({result: null, error}), {status: 400})
  }

  try {
    const data = deserialize({
      json:
        req.method === "POST"
          ? body.params
          : params.params // BUG: params only contains route segments (params.blitz), never params.params!
          ? parse(`${params.params}`)
          : undefined,
      meta:
        req.method === "POST"
          ? body.meta?.params
          : params.meta // BUG: always undefined!
          ? parse(`${params.meta}`)
          : undefined,
    })

### What are detailed steps to reproduce this?

1. Define a Blitz query configured with `httpMethod = "GET"`:
   ```typescript
   // src/queries/getUser.ts
   export default async function getUser(input: { id: number }) {
     return { id: input.id, name: "Alice" }
   }
   export const config = {
     httpMethod: "GET",
   }
  1. Mount the App Router RPC route in src/app/api/rpc/[[...blitz]]/route.ts:
    typescript
    import { rpcAppHandler } from "@blitzjs/rpc"
    export const { GET, POST, HEAD } = rpcAppHandler()
  2. Issue an HTTP GET request:
    bash
    curl -i -X GET "http://localhost:3000/api/rpc/getUser?params=%7B%22id%22%3A1%7D"
  3. Observe the terminal output: SyntaxError: Unexpected end of JSON input at handleRpcRequest.
  4. Observe the HTTP response: status is HTTP 200 (instead of 500), returning serialized error JSON as Content-Type: text/plain.

Run blitz -v and paste the output here:

Run blitz -v and paste the output here:

macOS / Windows / Linux
blitz: 3.0.2 (local)
@blitzjs/auth: 3.0.2 (local)
@blitzjs/next: 3.0.2 (local)
@blitzjs/rpc: 3.0.2 (local)

Please include below any other applicable logs and screenshots that show your problem:

Response Headers from Curl:

http
HTTP/1.1 200 OK
Content-Type: text/plain;charset=UTF-8
Content-Length: 135

{"result":null,"error":"SyntaxError: Unexpected end of JSON input"}

Proposed Fix (Pull Request diff):

diff
--- a/packages/blitz-rpc/src/index-server.ts
+++ b/packages/blitz-rpc/src/index-server.ts
@@ -402,26 +402,32 @@ export function rpcAppHandler(config?: RpcConfig) {
       req.method === "POST" ||
       (req.method === "GET" && resolverConfigWithDefaults.httpMethod === "GET")
     ) {
-      const body = await req.json()
-      if (req.method === "POST" && typeof body.params === "undefined") {
-        const error = {message: "Request body is missing the `params` key"}
-        rpcLogger.error(error.message)
-        return new Response(JSON.stringify({result: null, error}), {status: 400})
+      let body: any = {}
+      if (req.method === "POST") {
+        try {
+          body = await req.json()
+        } catch (e) {
+          body = {}
+        }
+        if (typeof body.params === "undefined") {
+          const error = {message: "Request body is missing the `params` key"}
+          rpcLogger.error(error.message)
+          return new Response(JSON.stringify({result: null, error}), {
+            status: 400,
+            headers: {"Content-Type": "application/json"},
+          })
+        }
       }
 
+      const url = new URL(req.url)
+      const queryParams = url.searchParams.get("params")
+      const queryMeta = url.searchParams.get("meta")
+
       try {
         const data = deserialize({
           json:
-            req.method === "POST"
-              ? body.params
-              : params.params
-              ? parse(`${params.params}`)
-              : undefined,
+            req.method === "POST" ? body.params : queryParams ? parse(queryParams) : undefined,
           meta:
-            req.method === "POST"
-              ? body.meta?.params
-              : params.meta
-              ? parse(`${params.meta}`)
-              : undefined,
+            req.method === "POST" ? body.meta?.params : queryMeta ? parse(queryMeta) : undefined,
         })
         rpcLogger.timer.initResolver()
@@ -444,6 +450,10 @@ export function rpcAppHandler(config?: RpcConfig) {
               result: serializedResult.meta,
             },
           }),
+          {
+            status: 200,
+            headers: {"Content-Type": "application/json"},
+          },
         )
         session?.setSession(response)
         return response
@@ -470,6 +480,10 @@ export function rpcAppHandler(config?: RpcConfig) {
               error: serializedError.meta,
             },
           }),
+          {
+            status: error.statusCode || 500,
+            headers: {"Content-Type": "application/json"},
+          },
         )
         session?.setSession(response)
         return response