feat(komoot): stop import on rate limit and reset pending activities

Signed-off-by: Marcus Fihlon <marcus@fihlon.swiss>
This commit is contained in:
Marcus Fihlon 2026-04-29 15:15:04 +02:00
parent 9a9785973d
commit 0a98aa523d
Signed by: McPringle
GPG key ID: C6B7F469EE363E1F

View file

@ -441,6 +441,7 @@
let importedCount = 0;
let failedCount = 0;
let cancelled = false;
let rateLimited = false;
const totalActivitiesToImport = activitiesToImport.length;
for (const [index, activity] of activitiesToImport.entries()) {
@ -455,6 +456,15 @@
body: buildImportPayload(activity.id)
});
if (response.status === 429) {
rateLimited = true;
activity.uiImportStatus = null;
activity.uiImportError = null;
resetQueuedActivities();
renderActivities(currentActivities);
break;
}
if (!response.ok) {
let message = 'Failed to import Komoot activity.';
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` : ''}.`);
} else {
showStatus(`Imported ${importedCount} Komoot activit${importedCount === 1 ? 'y' : 'ies'}${failedCount > 0 ? `, ${failedCount} failed` : ''}.`);