tinyhttp / milliparsec

🌌 Tiniest body parser in the universe. Built for modern Node.js
https://npm.im/milliparsec
MIT License
165 stars 7 forks source link

Shows error if json body is empty #10

Closed Kamrulhasan12345 closed 3 years ago

Kamrulhasan12345 commented 3 years ago

Hi, While making a post request I gave the header as application/json but kept the body empty and and it resulted it Unexpected end of JSON input. Then I checked the code and saw that there is no handling if json body is ''. Probably you could add try catch for these errors.

Hoping an early fix.

talentlessguy commented 3 years ago

What are the request headers?

Kamrulhasan12345 commented 3 years ago

Content-type set to application/json.

Kamrulhasan12345 commented 3 years ago

As seen in the code, I understood that json() only parses while this header is added and unless it doesn't

talentlessguy commented 3 years ago

@Kamrulhasan12345 should it be able to parse empty body then? it already expects to have JSON from you

Kamrulhasan12345 commented 3 years ago

@talentlessguy Thanks for making concept correct. Now I understood that my concept was wrong. Sorry for disturbing you.