From d4aaaecdec380854e507c5e9a026c0f6cd5fe382 Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Wed, 6 Nov 2024 11:29:10 -0800 Subject: [PATCH] OneNote: Display error message if there are several consecutive failed downloads --- src/formats/onenote.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/formats/onenote.ts b/src/formats/onenote.ts index 4c75e418..13e4fcf9 100644 --- a/src/formats/onenote.ts +++ b/src/formats/onenote.ts @@ -372,6 +372,7 @@ export class OneNoteImporter extends FormatImporter { progress.status('Starting OneNote import'); let progressTotal = 0; let progressCurrent = 0; + let consecutiveFailureCount = 0; for (let sectionId of this.selectedIds) { progress.reportProgress(progressCurrent, progressTotal); @@ -385,7 +386,17 @@ export class OneNoteImporter extends FormatImporter { const pagesUrl = `${baseUrl}?${params.toString()}`; - let pages: OnenotePage[] = ((await this.fetchResource(pagesUrl, 'json')).value); + let pages: OnenotePage[] | null = null; + try { + pages = ((await this.fetchResource(pagesUrl, 'json')).value); + } + catch (e) { + progress.status('Microsoft OneNote has limited how fast notes can be imported. Please try again in 30 minutes to continue importing.'); + return; + } + if (!pages) { + continue; + } progressTotal += pages.length; this.insertPagesToSection(pages, sectionId); @@ -418,11 +429,19 @@ export class OneNoteImporter extends FormatImporter { } progressCurrent++; - progress.reportProgress(progressCurrent, progressTotal); + consecutiveFailureCount = 0; } catch (e) { + consecutiveFailureCount++; progress.reportFailed(page.title, e.toString()); + + if (consecutiveFailureCount > 5) { + // Likely being rate limited. + progress.status('Microsoft OneNote has limited how fast notes can be imported. Please try again in 30 minutes to continue importing.'); + return; + } } + progress.reportProgress(progressCurrent, progressTotal); } } }