Skip to content

Commit 7b8fa7f

Browse files
committed
feat: retry
1 parent 5e5ca78 commit 7b8fa7f

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

libraries/nestjs-libraries/src/integrations/social.abstract.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export abstract class SocialAbstract {
2929

3030
public handleErrors(
3131
body: string
32-
): { type: 'refresh-token' | 'bad-body'; value: string } | undefined {
32+
):
33+
| { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
34+
| undefined {
3335
return undefined;
3436
}
3537

@@ -112,6 +114,11 @@ export abstract class SocialAbstract {
112114

113115
const handleError = this.handleErrors(json || '{}');
114116

117+
if (handleError?.type === 'retry') {
118+
await timer(5000);
119+
return this.fetch(url, options, identifier, totalRetries + 1);
120+
}
121+
115122
if (
116123
request.status === 401 &&
117124
(handleError?.type === 'refresh-token' || !handleError)

libraries/nestjs-libraries/src/integrations/social/instagram.provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,18 @@ export class InstagramProvider
4646

4747
public override handleErrors(body: string):
4848
| {
49-
type: 'refresh-token' | 'bad-body';
49+
type: 'refresh-token' | 'bad-body' | 'retry';
5050
value: string;
5151
}
5252
| undefined {
5353

54+
if (body.indexOf('An unknown error occurred') > -1) {
55+
return {
56+
type: 'retry' as const,
57+
value: 'An unknown error occurred, please try again later',
58+
};
59+
}
60+
5461
if (body.indexOf('REVOKED_ACCESS_TOKEN') > -1) {
5562
return {
5663
type: 'refresh-token' as const,

libraries/nestjs-libraries/src/integrations/social/instagram.standalone.provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class InstagramStandaloneProvider
3030

3131
editor = 'normal' as const;
3232

33-
public override handleErrors(body: string): { type: "refresh-token" | "bad-body"; value: string } | undefined {
33+
public override handleErrors(body: string): { type: "refresh-token" | "bad-body" | "retry"; value: string } | undefined {
3434
return instagramProvider.handleErrors(body);
3535
}
3636

0 commit comments

Comments
 (0)