Skip to content

Commit

Permalink
feat: add support for error property in stream (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Aug 22, 2024
1 parent e34bff9 commit 0c7d6e5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/ssestream/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"

"github.com/tidwall/gjson"
)

type Decoder interface {
Expand Down Expand Up @@ -144,6 +147,11 @@ func (s *Stream[T]) Next() bool {
}

if s.decoder.Event().Type == "" {
ep := gjson.GetBytes(s.decoder.Event().Data, "error")
if ep.Exists() {
s.err = fmt.Errorf("received error while streaming: %s", ep.String())
return false
}
s.err = json.Unmarshal(s.decoder.Event().Data, &s.cur)
if s.err != nil {
return false
Expand Down

0 comments on commit 0c7d6e5

Please sign in to comment.