feat: error handling that is not an http request
This commit is contained in:
parent
e46e661f02
commit
da77c227c1
|
|
@ -32,21 +32,30 @@ export abstract class SocialAbstract {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
public async mention(token: string, d: { query: string }, id: string, integration: Integration): Promise<{ id: string; label: string; image: string }[] | {none: true}> {
|
||||
return {none: true};
|
||||
public async mention(
|
||||
token: string,
|
||||
d: { query: string },
|
||||
id: string,
|
||||
integration: Integration
|
||||
): Promise<{ id: string; label: string; image: string }[] | { none: true }> {
|
||||
return { none: true };
|
||||
}
|
||||
|
||||
async runInConcurrent<T>(func: (...args: any[]) => Promise<T>) {
|
||||
const value = await concurrencyService<any>(this.identifier.split('-')[0], async () => {
|
||||
try {
|
||||
return await func();
|
||||
} catch (err) {
|
||||
return {type: 'error', value: err};
|
||||
const value = await concurrencyService<any>(
|
||||
this.identifier.split('-')[0],
|
||||
async () => {
|
||||
try {
|
||||
return await func();
|
||||
} catch (err) {
|
||||
const handle = this.handleErrors(JSON.stringify(err));
|
||||
return { err: true, ...(handle || {}) };
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
if (value && value.type === 'error') {
|
||||
throw value.value;
|
||||
if (value && value?.err && value?.value) {
|
||||
throw new BadBody('', JSON.stringify({}), {} as any, value.value || '');
|
||||
}
|
||||
|
||||
return value;
|
||||
|
|
@ -78,7 +87,11 @@ export abstract class SocialAbstract {
|
|||
json = '{}';
|
||||
}
|
||||
|
||||
if (request.status === 500 || json.includes('rate_limit_exceeded') || json.includes('Rate limit')) {
|
||||
if (
|
||||
request.status === 500 ||
|
||||
json.includes('rate_limit_exceeded') ||
|
||||
json.includes('Rate limit')
|
||||
) {
|
||||
await timer(5000);
|
||||
return this.fetch(url, options, identifier, totalRetries + 1);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,21 @@ export class XProvider extends SocialAbstract implements SocialProvider {
|
|||
|
||||
editor = 'normal' as const;
|
||||
|
||||
override handleErrors(body: string):
|
||||
| {
|
||||
type: 'refresh-token' | 'bad-body';
|
||||
value: string;
|
||||
}
|
||||
| undefined {
|
||||
if (body.includes('The Tweet contains an invalid URL.')) {
|
||||
return {
|
||||
type: 'bad-body',
|
||||
value: 'The Tweet contains a URL that is not allowed on X',
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@Plug({
|
||||
identifier: 'x-autoRepostPost',
|
||||
title: 'Auto Repost Posts',
|
||||
|
|
|
|||
Loading…
Reference in New Issue