pro-chat icon indicating copy to clipboard operation
pro-chat copied to clipboard

🧐[问题] How to handle stream errors, so that the UI can display the error?

Open KrishnaPG opened this issue 1 year ago • 0 comments

🧐 问题描述

When error happens in the streamed response, the ProChat UI should display it correctly. But Iam not sure how to implement such stream.

  const readableStream = new ReadableStream({
    start(controller) { 
      getAnswer()
       .then(data => controller.enqueue(textEncoder.encode(data)))
       .catch(ex) {
          controller.error(ex); <<--- this one throws error !!
       } 
       .finally(()=> controller.close())
    }
  }

Question: how to implement the ReadableStream correctly so that the errors are handled (and the ProChat UI shows the error).

Any help is greatly appreciated.

KrishnaPG avatar Jun 09 '24 01:06 KrishnaPG