You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I encountered an issue with the @hono/node-server library when attempting to access the getReader method on res.body. The method is not available, resulting in the following error:
TypeError: res.body.getReader is not a function at responseViaResponseObject (file:///home/pinna-marco-antonio/lili/back/node_modules/@hono/node-server/dist/index.mjs:420:29) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Server. (file:///home/pinna-marco-antonio/lili/back/node_modules/@hono/node-server/dist/index.mjs:551:14)
Code
Steps to Reproduce
Environment:
Node.js version: [Your Node.js version here, e.g. 18.17.0]
@hono/node-server version: [Library version here, e.g. 2.3.0]
Operating System: [Your OS, e.g. Ubuntu 22.04 or Windows 11]
Code example:
console.log(res.body.getReader());
A response from the server that includes an empty body triggers the issue.
Expected Behavior
The library should handle the res.body safely, ensuring that the response body can be processed without errors, even if it is empty or not a ReadableStream.
Current Behavior
The res.body object does not have a getReader method, which causes the application to throw a TypeError.
Possible Solution
To fix this issue, the res.body should be checked for the presence of the getReader method before calling it. Here's an example solution:
if(res.body&&typeofres.body.getReader==='function'){constreader=res.body.getReader();// Handle response stream here}else{console.warn('res.body does not support getReader');}ForstandardNode.jsstreams,analternativeapproachcouldbeusedtoreadtheresponsebodysafely.AdditionalNotesTheissuewasdiscoveredinthefollowingcontext:
AnincomingHTTPrequesttriggersa204NoContentresponse,whichdoesnothaveabody.ThelibrarythrowsaTypeErrorwhenattemptingtoprocessthisresponse.Pleaseletmeknowifyouneedfurtherdetails,orifIcanprovideaminimalreproductionrepositoryfordebugging.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Description
I encountered an issue with the
@hono/node-serverlibrary when attempting to access thegetReadermethod onres.body. The method is not available, resulting in the following error:TypeError: res.body.getReader is not a function at responseViaResponseObject (file:///home/pinna-marco-antonio/lili/back/node_modules/@hono/node-server/dist/index.mjs:420:29) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async Server. (file:///home/pinna-marco-antonio/lili/back/node_modules/@hono/node-server/dist/index.mjs:551:14)
Code
Steps to Reproduce
Expected Behavior
The library should handle the
res.bodysafely, ensuring that the response body can be processed without errors, even if it is empty or not aReadableStream.Current Behavior
The
res.bodyobject does not have agetReadermethod, which causes the application to throw aTypeError.Possible Solution
To fix this issue, the
res.bodyshould be checked for the presence of thegetReadermethod before calling it. Here's an example solution:Beta Was this translation helpful? Give feedback.
All reactions