Skip to content

Commit fe894b0

Browse files
Handle throttle headers (#160)
Check the throttle headers from the API to adjust the retry/backoff strategy. --------- Co-authored-by: fern-api <115122769+fern-api[bot]@users.noreply.github.com> Co-authored-by: Jay Vercellone <[email protected]>
1 parent dcc649a commit fe894b0

File tree

28 files changed

+696
-259
lines changed

28 files changed

+696
-259
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/sdk",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"private": false,
55
"repository": "github:PipedreamHQ/pipedream-sdk-typescript",
66
"type": "commonjs",

src/Client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export declare namespace PipedreamClient {
3232
/** Override the x-pd-environment header */
3333
projectEnvironment?: core.Supplier<Pipedream.ProjectEnvironment | undefined>;
3434
/** Additional headers to include in requests. */
35-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
35+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
3636
}
3737

3838
export interface RequestOptions {
@@ -47,7 +47,7 @@ export declare namespace PipedreamClient {
4747
/** Additional query string parameters to include in the request. */
4848
queryParams?: Record<string, unknown>;
4949
/** Additional headers to include in the request. */
50-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
50+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
5151
}
5252
}
5353

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
import * as errors from "../../errors/index.js";
6+
import * as core from "../../core/index.js";
7+
8+
export class TooManyRequestsError extends errors.PipedreamError {
9+
constructor(body?: unknown, rawResponse?: core.RawResponse) {
10+
super({
11+
message: "TooManyRequestsError",
12+
statusCode: 429,
13+
body: body,
14+
rawResponse: rawResponse,
15+
});
16+
Object.setPrototypeOf(this, TooManyRequestsError.prototype);
17+
}
18+
}

src/api/errors/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./TooManyRequestsError.js";

src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from "./resources/index.js";
22
export * from "./types/index.js";
3+
export * from "./errors/index.js";

src/api/resources/accounts/client/Client.ts

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export declare namespace Accounts {
1919
/** Override the x-pd-environment header */
2020
projectEnvironment?: core.Supplier<Pipedream.ProjectEnvironment | undefined>;
2121
/** Additional headers to include in requests. */
22-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
22+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
2323
}
2424

2525
export interface RequestOptions {
@@ -34,7 +34,7 @@ export declare namespace Accounts {
3434
/** Additional query string parameters to include in the request. */
3535
queryParams?: Record<string, unknown>;
3636
/** Additional headers to include in the request. */
37-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
37+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
3838
}
3939
}
4040

@@ -51,6 +51,8 @@ export class Accounts {
5151
* @param {Pipedream.AccountsListRequest} request
5252
* @param {Accounts.RequestOptions} requestOptions - Request-specific configuration.
5353
*
54+
* @throws {@link Pipedream.TooManyRequestsError}
55+
*
5456
* @example
5557
* await client.accounts.list()
5658
*/
@@ -121,11 +123,16 @@ export class Accounts {
121123
};
122124
}
123125
if (_response.error.reason === "status-code") {
124-
throw new errors.PipedreamError({
125-
statusCode: _response.error.statusCode,
126-
body: _response.error.body,
127-
rawResponse: _response.rawResponse,
128-
});
126+
switch (_response.error.statusCode) {
127+
case 429:
128+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
129+
default:
130+
throw new errors.PipedreamError({
131+
statusCode: _response.error.statusCode,
132+
body: _response.error.body,
133+
rawResponse: _response.rawResponse,
134+
});
135+
}
129136
}
130137
switch (_response.error.reason) {
131138
case "non-json":
@@ -166,6 +173,8 @@ export class Accounts {
166173
* @param {Pipedream.CreateAccountOpts} request
167174
* @param {Accounts.RequestOptions} requestOptions - Request-specific configuration.
168175
*
176+
* @throws {@link Pipedream.TooManyRequestsError}
177+
*
169178
* @example
170179
* await client.accounts.create({
171180
* appSlug: "app_slug",
@@ -240,11 +249,16 @@ export class Accounts {
240249
}
241250

242251
if (_response.error.reason === "status-code") {
243-
throw new errors.PipedreamError({
244-
statusCode: _response.error.statusCode,
245-
body: _response.error.body,
246-
rawResponse: _response.rawResponse,
247-
});
252+
switch (_response.error.statusCode) {
253+
case 429:
254+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
255+
default:
256+
throw new errors.PipedreamError({
257+
statusCode: _response.error.statusCode,
258+
body: _response.error.body,
259+
rawResponse: _response.rawResponse,
260+
});
261+
}
248262
}
249263

250264
switch (_response.error.reason) {
@@ -273,6 +287,8 @@ export class Accounts {
273287
* @param {Pipedream.AccountsRetrieveRequest} request
274288
* @param {Accounts.RequestOptions} requestOptions - Request-specific configuration.
275289
*
290+
* @throws {@link Pipedream.TooManyRequestsError}
291+
*
276292
* @example
277293
* await client.accounts.retrieve("account_id")
278294
*/
@@ -331,11 +347,16 @@ export class Accounts {
331347
}
332348

333349
if (_response.error.reason === "status-code") {
334-
throw new errors.PipedreamError({
335-
statusCode: _response.error.statusCode,
336-
body: _response.error.body,
337-
rawResponse: _response.rawResponse,
338-
});
350+
switch (_response.error.statusCode) {
351+
case 429:
352+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
353+
default:
354+
throw new errors.PipedreamError({
355+
statusCode: _response.error.statusCode,
356+
body: _response.error.body,
357+
rawResponse: _response.rawResponse,
358+
});
359+
}
339360
}
340361

341362
switch (_response.error.reason) {
@@ -363,6 +384,8 @@ export class Accounts {
363384
* @param {string} accountId
364385
* @param {Accounts.RequestOptions} requestOptions - Request-specific configuration.
365386
*
387+
* @throws {@link Pipedream.TooManyRequestsError}
388+
*
366389
* @example
367390
* await client.accounts.delete("account_id")
368391
*/
@@ -401,11 +424,16 @@ export class Accounts {
401424
}
402425

403426
if (_response.error.reason === "status-code") {
404-
throw new errors.PipedreamError({
405-
statusCode: _response.error.statusCode,
406-
body: _response.error.body,
407-
rawResponse: _response.rawResponse,
408-
});
427+
switch (_response.error.statusCode) {
428+
case 429:
429+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
430+
default:
431+
throw new errors.PipedreamError({
432+
statusCode: _response.error.statusCode,
433+
body: _response.error.body,
434+
rawResponse: _response.rawResponse,
435+
});
436+
}
409437
}
410438

411439
switch (_response.error.reason) {
@@ -433,6 +461,8 @@ export class Accounts {
433461
* @param {string} appId
434462
* @param {Accounts.RequestOptions} requestOptions - Request-specific configuration.
435463
*
464+
* @throws {@link Pipedream.TooManyRequestsError}
465+
*
436466
* @example
437467
* await client.accounts.deleteByApp("app_id")
438468
*/
@@ -471,11 +501,16 @@ export class Accounts {
471501
}
472502

473503
if (_response.error.reason === "status-code") {
474-
throw new errors.PipedreamError({
475-
statusCode: _response.error.statusCode,
476-
body: _response.error.body,
477-
rawResponse: _response.rawResponse,
478-
});
504+
switch (_response.error.statusCode) {
505+
case 429:
506+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
507+
default:
508+
throw new errors.PipedreamError({
509+
statusCode: _response.error.statusCode,
510+
body: _response.error.body,
511+
rawResponse: _response.rawResponse,
512+
});
513+
}
479514
}
480515

481516
switch (_response.error.reason) {

src/api/resources/actions/client/Client.ts

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export declare namespace Actions {
1919
/** Override the x-pd-environment header */
2020
projectEnvironment?: core.Supplier<Pipedream.ProjectEnvironment | undefined>;
2121
/** Additional headers to include in requests. */
22-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
22+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
2323
}
2424

2525
export interface RequestOptions {
@@ -34,7 +34,7 @@ export declare namespace Actions {
3434
/** Additional query string parameters to include in the request. */
3535
queryParams?: Record<string, unknown>;
3636
/** Additional headers to include in the request. */
37-
headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
37+
headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
3838
}
3939
}
4040

@@ -51,6 +51,8 @@ export class Actions {
5151
* @param {Pipedream.ActionsListRequest} request
5252
* @param {Actions.RequestOptions} requestOptions - Request-specific configuration.
5353
*
54+
* @throws {@link Pipedream.TooManyRequestsError}
55+
*
5456
* @example
5557
* await client.actions.list()
5658
*/
@@ -115,11 +117,16 @@ export class Actions {
115117
};
116118
}
117119
if (_response.error.reason === "status-code") {
118-
throw new errors.PipedreamError({
119-
statusCode: _response.error.statusCode,
120-
body: _response.error.body,
121-
rawResponse: _response.rawResponse,
122-
});
120+
switch (_response.error.statusCode) {
121+
case 429:
122+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
123+
default:
124+
throw new errors.PipedreamError({
125+
statusCode: _response.error.statusCode,
126+
body: _response.error.body,
127+
rawResponse: _response.rawResponse,
128+
});
129+
}
123130
}
124131
switch (_response.error.reason) {
125132
case "non-json":
@@ -160,6 +167,8 @@ export class Actions {
160167
* @param {string} componentId - The key that uniquely identifies the component (e.g., 'slack-send-message')
161168
* @param {Actions.RequestOptions} requestOptions - Request-specific configuration.
162169
*
170+
* @throws {@link Pipedream.TooManyRequestsError}
171+
*
163172
* @example
164173
* await client.actions.retrieve("component_id")
165174
*/
@@ -210,11 +219,16 @@ export class Actions {
210219
}
211220

212221
if (_response.error.reason === "status-code") {
213-
throw new errors.PipedreamError({
214-
statusCode: _response.error.statusCode,
215-
body: _response.error.body,
216-
rawResponse: _response.rawResponse,
217-
});
222+
switch (_response.error.statusCode) {
223+
case 429:
224+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
225+
default:
226+
throw new errors.PipedreamError({
227+
statusCode: _response.error.statusCode,
228+
body: _response.error.body,
229+
rawResponse: _response.rawResponse,
230+
});
231+
}
218232
}
219233

220234
switch (_response.error.reason) {
@@ -242,6 +256,8 @@ export class Actions {
242256
* @param {Pipedream.ConfigurePropOpts} request
243257
* @param {Actions.RequestOptions} requestOptions - Request-specific configuration.
244258
*
259+
* @throws {@link Pipedream.TooManyRequestsError}
260+
*
245261
* @example
246262
* await client.actions.configureProp({
247263
* id: "id",
@@ -302,11 +318,16 @@ export class Actions {
302318
}
303319

304320
if (_response.error.reason === "status-code") {
305-
throw new errors.PipedreamError({
306-
statusCode: _response.error.statusCode,
307-
body: _response.error.body,
308-
rawResponse: _response.rawResponse,
309-
});
321+
switch (_response.error.statusCode) {
322+
case 429:
323+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
324+
default:
325+
throw new errors.PipedreamError({
326+
statusCode: _response.error.statusCode,
327+
body: _response.error.body,
328+
rawResponse: _response.rawResponse,
329+
});
330+
}
310331
}
311332

312333
switch (_response.error.reason) {
@@ -334,6 +355,8 @@ export class Actions {
334355
* @param {Pipedream.ReloadPropsOpts} request
335356
* @param {Actions.RequestOptions} requestOptions - Request-specific configuration.
336357
*
358+
* @throws {@link Pipedream.TooManyRequestsError}
359+
*
337360
* @example
338361
* await client.actions.reloadProps({
339362
* id: "id",
@@ -393,11 +416,16 @@ export class Actions {
393416
}
394417

395418
if (_response.error.reason === "status-code") {
396-
throw new errors.PipedreamError({
397-
statusCode: _response.error.statusCode,
398-
body: _response.error.body,
399-
rawResponse: _response.rawResponse,
400-
});
419+
switch (_response.error.statusCode) {
420+
case 429:
421+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
422+
default:
423+
throw new errors.PipedreamError({
424+
statusCode: _response.error.statusCode,
425+
body: _response.error.body,
426+
rawResponse: _response.rawResponse,
427+
});
428+
}
401429
}
402430

403431
switch (_response.error.reason) {
@@ -425,6 +453,8 @@ export class Actions {
425453
* @param {Pipedream.RunActionOpts} request
426454
* @param {Actions.RequestOptions} requestOptions - Request-specific configuration.
427455
*
456+
* @throws {@link Pipedream.TooManyRequestsError}
457+
*
428458
* @example
429459
* await client.actions.run({
430460
* id: "id",
@@ -484,11 +514,16 @@ export class Actions {
484514
}
485515

486516
if (_response.error.reason === "status-code") {
487-
throw new errors.PipedreamError({
488-
statusCode: _response.error.statusCode,
489-
body: _response.error.body,
490-
rawResponse: _response.rawResponse,
491-
});
517+
switch (_response.error.statusCode) {
518+
case 429:
519+
throw new Pipedream.TooManyRequestsError(_response.error.body, _response.rawResponse);
520+
default:
521+
throw new errors.PipedreamError({
522+
statusCode: _response.error.statusCode,
523+
body: _response.error.body,
524+
rawResponse: _response.rawResponse,
525+
});
526+
}
492527
}
493528

494529
switch (_response.error.reason) {

0 commit comments

Comments
 (0)