#Best Practice reading body of request

1 messages · Page 1 of 1 (latest)

magic haven
#

Hi, I'm currently using version https://deno.land/[email protected]/http/server.ts. I'm trying to understand what is best practice when it comes to reading a body that may be empty. There doesn't appear to be a way to check if the body is empty with out attempting to read it via .json() or .text() and getting thrown an exception. That doesn't seem right. I've looked through the documentation, but I don't see anything or any way to see if the body is empty before attempting to read. Any suggestions?

left zinc
#

there is no way to do that; my suggestion is attempt read and catch the error

magic haven
#

yeah, that's what i have - just doesn't seem so graceful

stone pine
#

you could check if response.body is undefined, without trying to read it

karmic sand
magic haven
#

@stone pine, @left zinc Unfortunately, I tried that as well, it's never not null.

#

The closest thing I found about this is here:

#

If I'm understanding it correctly, It appears they want it always to not be null according to the statement on Nov 17 2021.