File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 7
7
import httpx
8
8
9
9
from ._types import ResponseT
10
+ from ._utils import is_mapping
11
+ from ._exceptions import APIError
10
12
11
13
if TYPE_CHECKING :
12
14
from ._base_client import SyncAPIClient , AsyncAPIClient
@@ -50,7 +52,15 @@ def __stream__(self) -> Iterator[ResponseT]:
50
52
break
51
53
52
54
if sse .event is None :
53
- yield process_data (data = sse .json (), cast_to = cast_to , response = response )
55
+ data = sse .json ()
56
+ if is_mapping (data ) and data .get ("error" ):
57
+ raise APIError (
58
+ message = "An error ocurred during streaming" ,
59
+ request = self .response .request ,
60
+ body = data ["error" ],
61
+ )
62
+
63
+ yield process_data (data = data , cast_to = cast_to , response = response )
54
64
55
65
56
66
class AsyncStream (Generic [ResponseT ]):
@@ -92,7 +102,15 @@ async def __stream__(self) -> AsyncIterator[ResponseT]:
92
102
break
93
103
94
104
if sse .event is None :
95
- yield process_data (data = sse .json (), cast_to = cast_to , response = response )
105
+ data = sse .json ()
106
+ if is_mapping (data ) and data .get ("error" ):
107
+ raise APIError (
108
+ message = "An error ocurred during streaming" ,
109
+ request = self .response .request ,
110
+ body = data ["error" ],
111
+ )
112
+
113
+ yield process_data (data = data , cast_to = cast_to , response = response )
96
114
97
115
98
116
class ServerSentEvent :
You can’t perform that action at this time.
0 commit comments