`Request` body reading functions: possible error types
This has a section saying:
⚠️ Be aware that the req.text() call can fail if the user hangs up the connection before the body is fully received. Make sure to handle this case. Do note this can happen in all methods that read from the request body, such as req.json(), req.formData(), req.arrayBuffer(), req.body.getReader().read(), req.body.pipeTo(), etc.I was wondering exactly which error gets thrown in this situation. Is it a NetworkError, or a TypeError, etc. I couldn't find any documentation (even in the spec) regarding what errors these body reading functions can throw. I have a use case that requires knowing exactly why the function failed. Thanks in advance!
HTTP Server APIs | Deno Docs
Deno currently has two HTTP Server APIs:
4 Replies
Apparently it's a generic
Error
when the connection hangs:
json()
throws SyntaxError
if it doesn't receive JSON
formData()
throws TypeError
if it doesn't receive form data
I think none of this is documented yetThank you so much! Is there a way I can reproduce this error manually?
I did it on Firefox by using the "network throttle" option or something to simulate a very slow connection. Then I send a reasonably big POST to the Deno webserver and close the FF tab before the payload is entirely sent
That's smart! Def will try this