Skip to content

Commit 5a35ff8

Browse files
committed
fix: Too Many Requests Toggl
1 parent c4b6c2d commit 5a35ff8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libs/toggl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
TimeEntry
1717
} from './toggl-types';
1818
import { EnrichedCustomer, EnrichedProject } from './types';
19-
import { initFetch, Logger } from './utils';
19+
import { initFetch, Logger, sleep } from './utils';
2020

2121
const BASE_URL = 'https://api.track.toggl.com/api/v8';
2222
const TIME_ENTRIES_PATH = 'time_entries';
@@ -291,6 +291,7 @@ export async function updateTogglClients() {
291291
({ name, notes }) =>
292292
notes === customer.sys.id || customer.fields.name === name
293293
);
294+
await sleep(1000);
294295
await fetch(`${BASE_URL}/${CLIENT_PATH}${found ? `/${found.id}` : ''}`, {
295296
method: found ? 'PUT' : 'POST',
296297
body: JSON.stringify({
@@ -306,6 +307,7 @@ export async function updateTogglClients() {
306307

307308
export async function updateTogglProjects() {
308309
const togglClients = await fetch<Customer[]>(`${BASE_URL}/${CLIENT_PATH}`);
310+
await sleep(1000);
309311
const togglProjects = await fetch<Project[]>(
310312
`${BASE_URL}/${WORKSPACE_PATH}/${WORKSPACE_ID}/${PROJECT_PATH}`
311313
);
@@ -317,6 +319,7 @@ export async function updateTogglProjects() {
317319
const togglProject = togglProjects.find(
318320
({ name, cid }) => cid === togglClient.id && project.fields.name === name
319321
);
322+
await sleep(1000);
320323
await fetch(
321324
`${BASE_URL}/${PROJECT_PATH}${togglProject ? `/${togglProject.id}` : ''}`,
322325
{

0 commit comments

Comments
 (0)