deno icon indicating copy to clipboard operation
deno copied to clipboard

request -> req.body returning true with no body?

Open avalero opened this issue 4 months ago • 5 comments

Version: Deno 2.0.0

With a simple Request this code fails when no body is received

if(req.body) {
   const body= await req.json();
   if (body.name) return new Response(`Hola ${body.name}`);
}

The Request has been made using Postman with body:none option checked

The error is

SyntaxError: Unexpected end of JSON input
    at parse (<anonymous>)
    at packageData (ext:deno_fetch/22_body.js:402:14)
    at consumeBody (ext:deno_fetch/22_body.js:260:12)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async handler (file:///C:/Users/ProfesorPR/deno/api1/main.ts:13:25)
    at async ext:deno_http/00_serve.ts:369:18

avalero avatar Oct 11 '24 14:10 avalero