Skip to content

Commit 5aa6911

Browse files
authored
Add error handling in createStreamBody
Fix unhandled 'error' event in createStreamBody, which caused Hono server to crash when attempting to serve an existing file without read permission. Now, such errors are properly handled to prevent server crashes.
1 parent f3156d9 commit 5aa6911

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/serve-static.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const createStreamBody = (stream: ReadStream) => {
3232
stream.on('data', (chunk) => {
3333
controller.enqueue(chunk)
3434
})
35+
stream.on('error', (err) => {
36+
controller.error(err)
37+
})
3538
stream.on('end', () => {
3639
controller.close()
3740
})

0 commit comments

Comments
 (0)