eventsource-parser icon indicating copy to clipboard operation
eventsource-parser copied to clipboard

How to catch parsing errors

Open ishandutta2007 opened this issue 4 months ago • 6 comments

How do I catch in such scenarios: str is rightly printed but when it enters parser.feed, it gets stuck and never returns; nor does it throw any errors. And hence it never reaches console.log("event", event) even

import { createParser } from 'eventsource-parser'
  const parser = createParser((event) => {
    console.log("event", event)
    if (event.type === 'event') {
      onMessage(event.data)
    }
  })
  for await (const chunk of streamAsyncIterable(resp.body!)) {
    const str = new TextDecoder().decode(chunk)
    console.log("str", str)
    parser.feed(str)
  }

resp is the respose object and onMessage is just a function

ishandutta2007 avatar Feb 13 '24 15:02 ishandutta2007