Skip to content

Commit 79bdc8d

Browse files
authored
Merge pull request #88 from PinataCloud/fix-try-catch-block-error-handling
fix: Add onrejected callback to then method in various analytics and file filter classes This update enhances the `.then()` method in multiple classes, including OptimizeImageCreateSignedUrl, OptimizeImageGetCid, AnalyticsBuilder, AnalyticsFilter, FilterFiles, FilterQueue, GroupsFilter, and FilterKeys, by adding an optional onrejected callback to handle promise rejections.
2 parents 84a69fd + ebca38b commit 79bdc8d

File tree

11 files changed

+237
-14
lines changed

11 files changed

+237
-14
lines changed

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- name: Setup Biome
1313
uses: biomejs/setup-biome@v2
1414
with:
15-
version: latest
15+
version: 1.9.4
1616
- name: Run Biome
1717
run: biome ci --formatter-enabled=true --linter-enabled=false --organize-imports-enabled=false src tests
1818
tests:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pinata",
3-
"version": "2.4.8",
3+
"version": "2.4.9",
44
"description": "The official Pinata SDK",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

src/core/classes/analytics/AnalyticsBuilder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ export class AnalyticsBuilder<T extends AnalyticsQuery, R> {
7272
throw new Error("getAnalytics method must be implemented in derived class");
7373
}
7474

75-
then(onfulfilled?: ((value: R) => any) | null): Promise<any> {
76-
return this.getAnalytics().then(onfulfilled);
75+
then(
76+
onfulfilled?: ((value: R) => any) | null,
77+
onrejected?: ((reason: any) => any) | null,
78+
): Promise<any> {
79+
return this.getAnalytics().then(onfulfilled, onrejected);
7780
}
7881
}

src/core/classes/analytics/AnalyticsFilter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ export class AnalyticsFilter {
9393

9494
then(
9595
onfulfilled?: ((value: TopAnalyticsResponse) => any) | null,
96+
onrejected?: ((reason: any) => any) | null,
9697
): Promise<any> {
97-
return analyticsTopUsage(this.config, this.query).then(onfulfilled);
98+
return analyticsTopUsage(this.config, this.query).then(
99+
onfulfilled,
100+
onrejected,
101+
);
98102
}
99103
}

src/core/classes/files/FilterFiles.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ export class FilterFiles {
7272
return this;
7373
}
7474

75-
then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any> {
76-
return this.fetchPage().then(onfulfilled);
75+
then(
76+
onfulfilled?: ((value: FileListResponse) => any) | null,
77+
onrejected?: ((reason: any) => any) | null,
78+
): Promise<any> {
79+
return this.fetchPage().then(onfulfilled, onrejected);
7780
}
7881

7982
private async fetchPage(): Promise<FileListResponse> {

src/core/classes/files/FilterQueue.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ export class FilterQueue {
6464
return this;
6565
}
6666

67-
then(onfulfilled?: ((value: PinQueueResponse) => any) | null): Promise<any> {
68-
return queue(this.config, this.query).then(onfulfilled);
67+
then(
68+
onfulfilled?: ((value: PinQueueResponse) => any) | null,
69+
onrejected?: ((reason: any) => any) | null,
70+
): Promise<any> {
71+
return queue(this.config, this.query).then(onfulfilled, onrejected);
6972
}
7073

7174
// rate limit, hopefully temporary?

src/core/classes/gateways/OptimizeImageCreateSignedUrl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ export class OptimizeImageCreateAccessLink {
2020
return this;
2121
}
2222

23-
then(onfulfilled?: ((value: string) => any) | null): Promise<any> {
23+
then(
24+
onfulfilled?: ((value: string) => any) | null,
25+
onrejected?: ((reason: any) => any) | null,
26+
): Promise<any> {
2427
return createAccessLink(this.config, this.urlOpts, this.imgOpts).then(
2528
onfulfilled,
29+
onrejected,
2630
);
2731
}
2832
}

src/core/classes/gateways/OptimizeImageGetCid.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ export class OptimizeImageGetCid {
2626
return this;
2727
}
2828

29-
then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any> {
29+
then(
30+
onfulfilled?: ((value: GetCIDResponse) => any) | null,
31+
onrejected?: ((reason: any) => any) | null,
32+
): Promise<any> {
3033
return getCid(this.config, this.cid, this.gatewayType, this.options).then(
3134
onfulfilled,
35+
onrejected,
3236
);
3337
}
3438
}

src/core/classes/groups/GroupsFilter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ export class FilterGroups {
4444

4545
then(
4646
onfulfilled?: ((value: GroupListResponse) => any) | null,
47+
onrejected?: ((reason: any) => any) | null,
4748
): Promise<GroupListResponse> {
4849
return this.fetchPage()
4950
.then((response) => {
5051
this.nextPageToken = response.next_page_token;
5152
return response;
5253
})
53-
.then(onfulfilled);
54+
.then(onfulfilled, onrejected);
5455
}
5556

5657
private async fetchPage(): Promise<GroupListResponse> {

src/core/classes/keys/FilterKeys.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@ export class FilterKeys {
3939
return this;
4040
}
4141

42-
then(onfulfilled?: ((value: KeyListItem[]) => any) | null): Promise<any> {
43-
return listKeys(this.config, this.query).then(onfulfilled);
42+
then(
43+
onfulfilled?: ((value: KeyListItem[]) => any) | null,
44+
onrejected?: ((reason: any) => any) | null,
45+
): Promise<any> {
46+
return listKeys(this.config, this.query).then(onfulfilled, onrejected);
4447
}
4548

4649
// private async rateLimit(): Promise<void> {

0 commit comments

Comments
 (0)