1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Chore: Wait when Discourse update fails

This commit is contained in:
Laurent Cozic 2023-12-13 19:39:04 +00:00
parent a730d349e4
commit 995423cadf

View File

@ -1,3 +1,4 @@
import { msleep } from '@joplin/utils/time';
import fetch from 'node-fetch';
interface ApiConfig {
@ -54,6 +55,7 @@ export const execApi = async (method: HttpMethod, path: string, body: Record<str
if (body) request.body = JSON.stringify(body);
while (true) {
const response = await fetch(`${config.baseUrl}/${path}`, request);
if (!response.ok) {
@ -65,12 +67,31 @@ export const execApi = async (method: HttpMethod, path: string, body: Record<str
} catch (error) {
// Ignore - it just means that the error object is a plain string
}
// {
// "errors": [
// "You’ve performed this action too many times. Please wait 39 seconds before trying again."
// ],
// "error_type": "rate_limit",
// "extras": {
// "wait_seconds": 39,
// "time_left": "39 seconds"
// }
// }
(error as any).apiObject = apiObject;
(error as any).status = response.status;
if (apiObject?.extras?.wait_seconds) {
await msleep(apiObject.extras.wait_seconds * 1000 + 1000);
continue;
}
throw error;
}
return response.json() as any;
}
};
export const getForumTopPostByExternalId = async (externalId: string): Promise<ForumTopPost> => {