Skip to content

How to escalate stream error when throwing? #3834

Answered by EdamAme-x
charnould asked this question in Q&A
Discussion options

You must be logged in to vote

Please try to use this

app.get('/stream', (c) => {
  return stream(
    c,
    async (stream) => {
      // Write a process to be executed when aborted.
      stream.onAbort(() => {
        console.log('Aborted!')
      })
      // Write a Uint8Array.
      await stream.write(
        new Uint8Array([0x48, 0x65, 0x6c, 0x6c, 0x6f])
      )
      // Pipe a readable stream.
      await stream.pipe(anotherReadableStream)
    },
    (err, stream) => {
      // return error page here
      stream.writeln('An error occurred!')
      console.error(err)
    }
  )
})

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@charnould
Comment options

Answer selected by charnould
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants