mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Chore: Wait when Discourse update fails
This commit is contained in:
parent
a730d349e4
commit
995423cadf
@ -1,3 +1,4 @@
|
|||||||
|
import { msleep } from '@joplin/utils/time';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
|
|
||||||
interface ApiConfig {
|
interface ApiConfig {
|
||||||
@ -54,6 +55,7 @@ export const execApi = async (method: HttpMethod, path: string, body: Record<str
|
|||||||
|
|
||||||
if (body) request.body = JSON.stringify(body);
|
if (body) request.body = JSON.stringify(body);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
const response = await fetch(`${config.baseUrl}/${path}`, request);
|
const response = await fetch(`${config.baseUrl}/${path}`, request);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@ -65,12 +67,31 @@ export const execApi = async (method: HttpMethod, path: string, body: Record<str
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Ignore - it just means that the error object is a plain string
|
// 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).apiObject = apiObject;
|
||||||
(error as any).status = response.status;
|
(error as any).status = response.status;
|
||||||
|
|
||||||
|
if (apiObject?.extras?.wait_seconds) {
|
||||||
|
await msleep(apiObject.extras.wait_seconds * 1000 + 1000);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json() as any;
|
return response.json() as any;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getForumTopPostByExternalId = async (externalId: string): Promise<ForumTopPost> => {
|
export const getForumTopPostByExternalId = async (externalId: string): Promise<ForumTopPost> => {
|
||||||
|
Loading…
Reference in New Issue
Block a user