Skip to content

Commit 29f4b5d

Browse files
authored
Fix missing error handling in _request_stream
1 parent 7b9bfd3 commit 29f4b5d

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/lara_sdk/_client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,13 @@ def _request(self, method: str, path: str, body: Dict = None, files: Dict = None
155155
else:
156156
response = self.session.request('POST', f'{self.base_url}{path}', headers=_headers, json=body)
157157

158-
if 200 <= response.status_code < 300:
159-
if "text/csv" in response.headers.get('Content-Type', ''):
160-
return response.content
161-
return response.json().get('content', None)
162-
raise LaraApiError.from_response(response)
158+
if not (200 <= response.status_code < 300):
159+
raise LaraApiError.from_response(response)
160+
161+
if "text/csv" in response.headers.get('Content-Type', ''):
162+
return response.content
163+
164+
return response.json().get('content', None)
163165

164166
def _request_stream(self, method: str, path: str, body: Dict = None, files: Dict = None, headers: Dict = None):
165167
if not path.startswith('/'):
@@ -187,6 +189,9 @@ def _request_stream(self, method: str, path: str, body: Dict = None, files: Dict
187189
else:
188190
response = self.session.request('POST', f'{self.base_url}{path}', headers=_headers, json=body, stream=True)
189191

192+
if not (200 <= response.status_code < 300):
193+
raise LaraApiError.from_response(response)
194+
190195
buffer = ''
191196
for chunk in response.iter_content(chunk_size=None, decode_unicode=True):
192197
if chunk:

0 commit comments

Comments
 (0)