From 42c15bd76f3abd631ce16cd07b6251f22838be76 Mon Sep 17 00:00:00 2001 From: Isa Herico Velasco <7840857+iisa@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:36:22 -0800 Subject: [PATCH 1/2] text wrapper - add try/catch to request with 3 retries --- src/plugins/tts/PageChunk.js | 41 +++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/plugins/tts/PageChunk.js b/src/plugins/tts/PageChunk.js index c69510390..2eddd1559 100644 --- a/src/plugins/tts/PageChunk.js +++ b/src/plugins/tts/PageChunk.js @@ -1,3 +1,5 @@ +import { sleep } from "@/src/BookReader/utils"; + /** * Class to manage a 'chunk' (approximately a paragraph) of text on a page. */ @@ -19,19 +21,38 @@ export default class PageChunk { * @param {string} server * @param {string} bookPath * @param {number} leafIndex + * @param {number} retryCount * @return {Promise} */ - static async fetch(server, bookPath, leafIndex) { - const chunks = await $.ajax({ - type: 'GET', - url: `https://${server}/BookReader/BookReaderGetTextWrapper.php`, - dataType:'jsonp', - cache: true, - data: { - path: `${bookPath}_djvu.xml`, - page: leafIndex + static async fetch(server, bookPath, leafIndex, retryCount = 0) { + let chunks = []; + // try 3 times + if (retryCount === 3) { + return chunks; //empty chunks + } + if (retryCount > 0) { + await sleep(700); + } + + try { + chunks = await $.ajax({ + type: 'GET', + url: `https://${server}/BookReader/BookReaderGetTextWrapper.php`, + dataType:'jsonp', + cache: true, + data: { + path: `${bookPath}_djvu.xml`, + page: leafIndex + } + }); + } catch (e) { + const newRetryCount = retryCount + 1; + if (window.Sentry) { + window.Sentry?.captureException(e); } - }); + return PageChunk.fetch(server, bookPath, leafIndex, newRetryCount); + } + return PageChunk._fromTextWrapperResponse(leafIndex, chunks); } From 5bcc1ebc9642854c2f3a9bd4da358b6d07385bac Mon Sep 17 00:00:00 2001 From: Isa Herico Velasco <7840857+iisa@users.noreply.github.com> Date: Wed, 30 Nov 2022 10:00:48 -0800 Subject: [PATCH 2/2] return promise w empty chunks --- src/plugins/tts/PageChunk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/tts/PageChunk.js b/src/plugins/tts/PageChunk.js index 2eddd1559..972e3b6ce 100644 --- a/src/plugins/tts/PageChunk.js +++ b/src/plugins/tts/PageChunk.js @@ -28,7 +28,7 @@ export default class PageChunk { let chunks = []; // try 3 times if (retryCount === 3) { - return chunks; //empty chunks + return PageChunk._fromTextWrapperResponse(leafIndex, chunks); //empty chunks } if (retryCount > 0) { await sleep(700);