feat(komoot): stop import on rate limit and reset pending activities
Signed-off-by: Marcus Fihlon <marcus@fihlon.swiss>
This commit is contained in:
parent
9a9785973d
commit
0a98aa523d
1 changed files with 13 additions and 1 deletions
|
|
@ -441,6 +441,7 @@
|
||||||
let importedCount = 0;
|
let importedCount = 0;
|
||||||
let failedCount = 0;
|
let failedCount = 0;
|
||||||
let cancelled = false;
|
let cancelled = false;
|
||||||
|
let rateLimited = false;
|
||||||
const totalActivitiesToImport = activitiesToImport.length;
|
const totalActivitiesToImport = activitiesToImport.length;
|
||||||
|
|
||||||
for (const [index, activity] of activitiesToImport.entries()) {
|
for (const [index, activity] of activitiesToImport.entries()) {
|
||||||
|
|
@ -455,6 +456,15 @@
|
||||||
body: buildImportPayload(activity.id)
|
body: buildImportPayload(activity.id)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (response.status === 429) {
|
||||||
|
rateLimited = true;
|
||||||
|
activity.uiImportStatus = null;
|
||||||
|
activity.uiImportError = null;
|
||||||
|
resetQueuedActivities();
|
||||||
|
renderActivities(currentActivities);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
let message = 'Failed to import Komoot activity.';
|
let message = 'Failed to import Komoot activity.';
|
||||||
try {
|
try {
|
||||||
|
|
@ -490,7 +500,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cancelled) {
|
if (rateLimited) {
|
||||||
|
showStatus('Komoot rate limit reached. Import stopped. Please try again later.');
|
||||||
|
} else if (cancelled) {
|
||||||
showStatus(`Import stopped after the current activity. Imported ${importedCount} Komoot activit${importedCount === 1 ? 'y' : 'ies'}${failedCount > 0 ? `, ${failedCount} failed` : ''}.`);
|
showStatus(`Import stopped after the current activity. Imported ${importedCount} Komoot activit${importedCount === 1 ? 'y' : 'ies'}${failedCount > 0 ? `, ${failedCount} failed` : ''}.`);
|
||||||
} else {
|
} else {
|
||||||
showStatus(`Imported ${importedCount} Komoot activit${importedCount === 1 ? 'y' : 'ies'}${failedCount > 0 ? `, ${failedCount} failed` : ''}.`);
|
showStatus(`Imported ${importedCount} Komoot activit${importedCount === 1 ? 'y' : 'ies'}${failedCount > 0 ? `, ${failedCount} failed` : ''}.`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue