Skip to content

Commit 81fdaa4

Browse files
Handle throttled responses (#137)
Handle responses with the `429 Too Many Requests` status code. --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Jay Vercellone <[email protected]>
1 parent 4166610 commit 81fdaa4

File tree

19 files changed

+896
-6
lines changed

19 files changed

+896
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ from pipedream import Pipedream
175175
client = Pipedream(
176176
...,
177177
httpx_client=httpx.Client(
178-
proxies="http://my.test.proxy.example.com",
178+
proxy="http://my.test.proxy.example.com",
179179
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
180180
),
181181
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "pipedream"
33

44
[tool.poetry]
55
name = "pipedream"
6-
version = "1.0.6"
6+
version = "1.0.7"
77
description = ""
88
readme = "README.md"
99
authors = []

src/pipedream/accounts/raw_client.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from ..core.pagination import AsyncPager, BaseHttpResponse, SyncPager
1111
from ..core.pydantic_utilities import parse_obj_as
1212
from ..core.request_options import RequestOptions
13+
from ..errors.too_many_requests_error import TooManyRequestsError
1314
from ..types.account import Account
1415
from ..types.list_accounts_response import ListAccountsResponse
1516

@@ -108,6 +109,17 @@ def list(
108109
return SyncPager(
109110
has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response)
110111
)
112+
if _response.status_code == 429:
113+
raise TooManyRequestsError(
114+
headers=dict(_response.headers),
115+
body=typing.cast(
116+
typing.Optional[typing.Any],
117+
parse_obj_as(
118+
type_=typing.Optional[typing.Any], # type: ignore
119+
object_=_response.json(),
120+
),
121+
),
122+
)
111123
_response_json = _response.json()
112124
except JSONDecodeError:
113125
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -188,6 +200,17 @@ def create(
188200
),
189201
)
190202
return HttpResponse(response=_response, data=_data)
203+
if _response.status_code == 429:
204+
raise TooManyRequestsError(
205+
headers=dict(_response.headers),
206+
body=typing.cast(
207+
typing.Optional[typing.Any],
208+
parse_obj_as(
209+
type_=typing.Optional[typing.Any], # type: ignore
210+
object_=_response.json(),
211+
),
212+
),
213+
)
191214
_response_json = _response.json()
192215
except JSONDecodeError:
193216
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -236,6 +259,17 @@ def retrieve(
236259
),
237260
)
238261
return HttpResponse(response=_response, data=_data)
262+
if _response.status_code == 429:
263+
raise TooManyRequestsError(
264+
headers=dict(_response.headers),
265+
body=typing.cast(
266+
typing.Optional[typing.Any],
267+
parse_obj_as(
268+
type_=typing.Optional[typing.Any], # type: ignore
269+
object_=_response.json(),
270+
),
271+
),
272+
)
239273
_response_json = _response.json()
240274
except JSONDecodeError:
241275
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -264,6 +298,17 @@ def delete(self, account_id: str, *, request_options: typing.Optional[RequestOpt
264298
try:
265299
if 200 <= _response.status_code < 300:
266300
return HttpResponse(response=_response, data=None)
301+
if _response.status_code == 429:
302+
raise TooManyRequestsError(
303+
headers=dict(_response.headers),
304+
body=typing.cast(
305+
typing.Optional[typing.Any],
306+
parse_obj_as(
307+
type_=typing.Optional[typing.Any], # type: ignore
308+
object_=_response.json(),
309+
),
310+
),
311+
)
267312
_response_json = _response.json()
268313
except JSONDecodeError:
269314
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -294,6 +339,17 @@ def delete_by_app(
294339
try:
295340
if 200 <= _response.status_code < 300:
296341
return HttpResponse(response=_response, data=None)
342+
if _response.status_code == 429:
343+
raise TooManyRequestsError(
344+
headers=dict(_response.headers),
345+
body=typing.cast(
346+
typing.Optional[typing.Any],
347+
parse_obj_as(
348+
type_=typing.Optional[typing.Any], # type: ignore
349+
object_=_response.json(),
350+
),
351+
),
352+
)
297353
_response_json = _response.json()
298354
except JSONDecodeError:
299355
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -394,6 +450,17 @@ async def _get_next():
394450
return AsyncPager(
395451
has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response)
396452
)
453+
if _response.status_code == 429:
454+
raise TooManyRequestsError(
455+
headers=dict(_response.headers),
456+
body=typing.cast(
457+
typing.Optional[typing.Any],
458+
parse_obj_as(
459+
type_=typing.Optional[typing.Any], # type: ignore
460+
object_=_response.json(),
461+
),
462+
),
463+
)
397464
_response_json = _response.json()
398465
except JSONDecodeError:
399466
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -474,6 +541,17 @@ async def create(
474541
),
475542
)
476543
return AsyncHttpResponse(response=_response, data=_data)
544+
if _response.status_code == 429:
545+
raise TooManyRequestsError(
546+
headers=dict(_response.headers),
547+
body=typing.cast(
548+
typing.Optional[typing.Any],
549+
parse_obj_as(
550+
type_=typing.Optional[typing.Any], # type: ignore
551+
object_=_response.json(),
552+
),
553+
),
554+
)
477555
_response_json = _response.json()
478556
except JSONDecodeError:
479557
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -522,6 +600,17 @@ async def retrieve(
522600
),
523601
)
524602
return AsyncHttpResponse(response=_response, data=_data)
603+
if _response.status_code == 429:
604+
raise TooManyRequestsError(
605+
headers=dict(_response.headers),
606+
body=typing.cast(
607+
typing.Optional[typing.Any],
608+
parse_obj_as(
609+
type_=typing.Optional[typing.Any], # type: ignore
610+
object_=_response.json(),
611+
),
612+
),
613+
)
525614
_response_json = _response.json()
526615
except JSONDecodeError:
527616
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -552,6 +641,17 @@ async def delete(
552641
try:
553642
if 200 <= _response.status_code < 300:
554643
return AsyncHttpResponse(response=_response, data=None)
644+
if _response.status_code == 429:
645+
raise TooManyRequestsError(
646+
headers=dict(_response.headers),
647+
body=typing.cast(
648+
typing.Optional[typing.Any],
649+
parse_obj_as(
650+
type_=typing.Optional[typing.Any], # type: ignore
651+
object_=_response.json(),
652+
),
653+
),
654+
)
555655
_response_json = _response.json()
556656
except JSONDecodeError:
557657
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -582,6 +682,17 @@ async def delete_by_app(
582682
try:
583683
if 200 <= _response.status_code < 300:
584684
return AsyncHttpResponse(response=_response, data=None)
685+
if _response.status_code == 429:
686+
raise TooManyRequestsError(
687+
headers=dict(_response.headers),
688+
body=typing.cast(
689+
typing.Optional[typing.Any],
690+
parse_obj_as(
691+
type_=typing.Optional[typing.Any], # type: ignore
692+
object_=_response.json(),
693+
),
694+
),
695+
)
585696
_response_json = _response.json()
586697
except JSONDecodeError:
587698
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)

src/pipedream/actions/raw_client.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from ..core.pydantic_utilities import parse_obj_as
1212
from ..core.request_options import RequestOptions
1313
from ..core.serialization import convert_and_respect_annotation_metadata
14+
from ..errors.too_many_requests_error import TooManyRequestsError
1415
from ..types.component import Component
1516
from ..types.configure_prop_response import ConfigurePropResponse
1617
from ..types.configured_props import ConfiguredProps
@@ -104,6 +105,17 @@ def list(
104105
return SyncPager(
105106
has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response)
106107
)
108+
if _response.status_code == 429:
109+
raise TooManyRequestsError(
110+
headers=dict(_response.headers),
111+
body=typing.cast(
112+
typing.Optional[typing.Any],
113+
parse_obj_as(
114+
type_=typing.Optional[typing.Any], # type: ignore
115+
object_=_response.json(),
116+
),
117+
),
118+
)
107119
_response_json = _response.json()
108120
except JSONDecodeError:
109121
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -144,6 +156,17 @@ def retrieve(
144156
)
145157
_data = _parsed_response.data
146158
return HttpResponse(response=_response, data=_data)
159+
if _response.status_code == 429:
160+
raise TooManyRequestsError(
161+
headers=dict(_response.headers),
162+
body=typing.cast(
163+
typing.Optional[typing.Any],
164+
parse_obj_as(
165+
type_=typing.Optional[typing.Any], # type: ignore
166+
object_=_response.json(),
167+
),
168+
),
169+
)
147170
_response_json = _response.json()
148171
except JSONDecodeError:
149172
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -234,6 +257,17 @@ def configure_prop(
234257
),
235258
)
236259
return HttpResponse(response=_response, data=_data)
260+
if _response.status_code == 429:
261+
raise TooManyRequestsError(
262+
headers=dict(_response.headers),
263+
body=typing.cast(
264+
typing.Optional[typing.Any],
265+
parse_obj_as(
266+
type_=typing.Optional[typing.Any], # type: ignore
267+
object_=_response.json(),
268+
),
269+
),
270+
)
237271
_response_json = _response.json()
238272
except JSONDecodeError:
239273
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -304,6 +338,17 @@ def reload_props(
304338
),
305339
)
306340
return HttpResponse(response=_response, data=_data)
341+
if _response.status_code == 429:
342+
raise TooManyRequestsError(
343+
headers=dict(_response.headers),
344+
body=typing.cast(
345+
typing.Optional[typing.Any],
346+
parse_obj_as(
347+
type_=typing.Optional[typing.Any], # type: ignore
348+
object_=_response.json(),
349+
),
350+
),
351+
)
307352
_response_json = _response.json()
308353
except JSONDecodeError:
309354
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -375,6 +420,17 @@ def run(
375420
),
376421
)
377422
return HttpResponse(response=_response, data=_data)
423+
if _response.status_code == 429:
424+
raise TooManyRequestsError(
425+
headers=dict(_response.headers),
426+
body=typing.cast(
427+
typing.Optional[typing.Any],
428+
parse_obj_as(
429+
type_=typing.Optional[typing.Any], # type: ignore
430+
object_=_response.json(),
431+
),
432+
),
433+
)
378434
_response_json = _response.json()
379435
except JSONDecodeError:
380436
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -464,6 +520,17 @@ async def _get_next():
464520
return AsyncPager(
465521
has_next=_has_next, items=_items, get_next=_get_next, response=BaseHttpResponse(response=_response)
466522
)
523+
if _response.status_code == 429:
524+
raise TooManyRequestsError(
525+
headers=dict(_response.headers),
526+
body=typing.cast(
527+
typing.Optional[typing.Any],
528+
parse_obj_as(
529+
type_=typing.Optional[typing.Any], # type: ignore
530+
object_=_response.json(),
531+
),
532+
),
533+
)
467534
_response_json = _response.json()
468535
except JSONDecodeError:
469536
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -504,6 +571,17 @@ async def retrieve(
504571
)
505572
_data = _parsed_response.data
506573
return AsyncHttpResponse(response=_response, data=_data)
574+
if _response.status_code == 429:
575+
raise TooManyRequestsError(
576+
headers=dict(_response.headers),
577+
body=typing.cast(
578+
typing.Optional[typing.Any],
579+
parse_obj_as(
580+
type_=typing.Optional[typing.Any], # type: ignore
581+
object_=_response.json(),
582+
),
583+
),
584+
)
507585
_response_json = _response.json()
508586
except JSONDecodeError:
509587
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -594,6 +672,17 @@ async def configure_prop(
594672
),
595673
)
596674
return AsyncHttpResponse(response=_response, data=_data)
675+
if _response.status_code == 429:
676+
raise TooManyRequestsError(
677+
headers=dict(_response.headers),
678+
body=typing.cast(
679+
typing.Optional[typing.Any],
680+
parse_obj_as(
681+
type_=typing.Optional[typing.Any], # type: ignore
682+
object_=_response.json(),
683+
),
684+
),
685+
)
597686
_response_json = _response.json()
598687
except JSONDecodeError:
599688
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -664,6 +753,17 @@ async def reload_props(
664753
),
665754
)
666755
return AsyncHttpResponse(response=_response, data=_data)
756+
if _response.status_code == 429:
757+
raise TooManyRequestsError(
758+
headers=dict(_response.headers),
759+
body=typing.cast(
760+
typing.Optional[typing.Any],
761+
parse_obj_as(
762+
type_=typing.Optional[typing.Any], # type: ignore
763+
object_=_response.json(),
764+
),
765+
),
766+
)
667767
_response_json = _response.json()
668768
except JSONDecodeError:
669769
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
@@ -735,6 +835,17 @@ async def run(
735835
),
736836
)
737837
return AsyncHttpResponse(response=_response, data=_data)
838+
if _response.status_code == 429:
839+
raise TooManyRequestsError(
840+
headers=dict(_response.headers),
841+
body=typing.cast(
842+
typing.Optional[typing.Any],
843+
parse_obj_as(
844+
type_=typing.Optional[typing.Any], # type: ignore
845+
object_=_response.json(),
846+
),
847+
),
848+
)
738849
_response_json = _response.json()
739850
except JSONDecodeError:
740851
raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)

0 commit comments

Comments
 (0)