feat: retry

This commit is contained in:
Nevo David 2025-08-14 11:38:27 +07:00
parent 5e5ca78e9a
commit 7b8fa7fb7b
3 changed files with 17 additions and 3 deletions

View File

@ -29,7 +29,9 @@ export abstract class SocialAbstract {
public handleErrors(
body: string
): { type: 'refresh-token' | 'bad-body'; value: string } | undefined {
):
| { type: 'refresh-token' | 'bad-body' | 'retry'; value: string }
| undefined {
return undefined;
}
@ -112,6 +114,11 @@ export abstract class SocialAbstract {
const handleError = this.handleErrors(json || '{}');
if (handleError?.type === 'retry') {
await timer(5000);
return this.fetch(url, options, identifier, totalRetries + 1);
}
if (
request.status === 401 &&
(handleError?.type === 'refresh-token' || !handleError)

View File

@ -46,11 +46,18 @@ export class InstagramProvider
public override handleErrors(body: string):
| {
type: 'refresh-token' | 'bad-body';
type: 'refresh-token' | 'bad-body' | 'retry';
value: string;
}
| undefined {
if (body.indexOf('An unknown error occurred') > -1) {
return {
type: 'retry' as const,
value: 'An unknown error occurred, please try again later',
};
}
if (body.indexOf('REVOKED_ACCESS_TOKEN') > -1) {
return {
type: 'refresh-token' as const,

View File

@ -30,7 +30,7 @@ export class InstagramStandaloneProvider
editor = 'normal' as const;
public override handleErrors(body: string): { type: "refresh-token" | "bad-body"; value: string } | undefined {
public override handleErrors(body: string): { type: "refresh-token" | "bad-body" | "retry"; value: string } | undefined {
return instagramProvider.handleErrors(body);
}