Skip to content

Commit 73f9342

Browse files
stainless-app[bot]stainless-bot
authored andcommitted
feat: add support for error property in stream (#29)
1 parent e34bff9 commit 73f9342

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/ssestream/streaming.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66
"bufio"
77
"bytes"
88
"encoding/json"
9+
"fmt"
910
"io"
1011
"net/http"
1112
"strings"
13+
14+
"github.com/tidwall/gjson"
1215
)
1316

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

146149
if s.decoder.Event().Type == "" {
150+
ep := gjson.GetBytes(s.decoder.Event().Data, "error")
151+
if ep.Exists() {
152+
s.err = fmt.Errorf("received error while streaming: %s", ep.String())
153+
return false
154+
}
147155
s.err = json.Unmarshal(s.decoder.Event().Data, &s.cur)
148156
if s.err != nil {
149157
return false

0 commit comments

Comments
 (0)