-
Notifications
You must be signed in to change notification settings - Fork 0
ETT-1411: additional error handling and matomo custom events #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,6 +64,8 @@ | |
| let errorCount = 0; | ||
| let downloadError = $state(false); | ||
| let downloadErrorMessage = $state(''); | ||
| let progressError; | ||
| let closeDownloadModal = false; | ||
|
|
||
| const _mtm = (window._mtm = window._mtm || []); | ||
|
|
||
|
|
@@ -101,9 +103,10 @@ | |
| console.log('-- download.callback cancel download'); | ||
| clearInterval(trackerInterval); | ||
| trackerInterval = null; | ||
| modal.hide(); | ||
| if (closeDownloadModal) modal.hide(); | ||
| document.getElementById('submit-download').focus(); | ||
| } | ||
| closeDownloadModal = false; | ||
| } | ||
|
|
||
| function checkStatusInterval() { | ||
|
|
@@ -120,12 +123,21 @@ | |
| if (status.done) { | ||
| clearInterval(trackerInterval); | ||
| trackerInterval = null; | ||
| } | ||
| } | ||
| }) | ||
| .catch((error) => { | ||
| console.error('Progress check error:', error); | ||
| console.error('Error with imgsrv', error); | ||
| numAttempts += 1; | ||
| errorCount++; | ||
|
|
||
| if (progressError) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When there's an error with |
||
| clearInterval(trackerInterval); | ||
| trackerInterval = null; | ||
| downloadInProgress = false; | ||
| downloadError = true; | ||
| downloadErrorMessage = `Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.`; | ||
| HT.live.announce(`${downloadErrorMessage.replace(/<\/?[^>]+(>|$)/g, "")}${' '.repeat(errorCount)}`); | ||
| } | ||
|
|
||
| // Stop polling after too many failures | ||
| if (numAttempts > 3) { | ||
|
|
@@ -135,20 +147,25 @@ | |
| downloadError = true; | ||
| downloadErrorMessage = `Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.`; | ||
| HT.live.announce(`${downloadErrorMessage.replace(/<\/?[^>]+(>|$)/g, "")}${' '.repeat(errorCount)}`); | ||
| status.error = true; | ||
| _mtm.push({'event': 'pt-large-download-error', 'downloadUrl': `${progressUrl.toString()}`}); | ||
| _mtm.push({'event': 'pt-download-error','errorType': 'imgsrv unreachable', 'downloadUrl': `${progressUrl.toString()}`}); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| function updateProgress(data) { | ||
| progressError = false; | ||
| let percent; | ||
| let current = data.status; | ||
| if (current == 'EOT' || current == 'DONE') { | ||
| if (current == 'EOT' || (current == 'DONE' && data.current_page == -1)) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scenario 1: The real DONE status is always accompanied by a |
||
| status.done = true; | ||
| percent = 100; | ||
| downloadInProgress = false; | ||
| HT.live.announce(`All done! Your ${formatTitle[format]} is ready for download.`); | ||
| } else if (current == 'DONE' && !data.current_page) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scenario 2: The response that comes back from |
||
| console.log('weird progress bug, set downloads to false, throw error') | ||
| progressError = true; | ||
| _mtm.push({'event': 'pt-download-error', 'errorType': 'imgsrv: no download found', 'downloadUrl': `${progressUrl.toString()}`}); | ||
| throw new Error(`imgsrv: "No download found"`); | ||
| } else { | ||
| status.done = false; | ||
| current = data.current_page; | ||
|
|
@@ -160,8 +177,12 @@ | |
| } else { | ||
| numAttempts += 1; | ||
| } | ||
| if (numAttempts > 100) { | ||
| status.error = true; | ||
| if (numAttempts > 5) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Scenario 3: Changed this from 100 to 5 attempts and replaced the bogus |
||
| console.log('cancelling from updateProgress'); | ||
| progressError = true; | ||
| cancelDownload(false); | ||
| _mtm.push({'event': 'pt-download-error', 'errorType': 'too many attempts to download same page', 'downloadUrl': `${progressUrl.toString()}`}); | ||
| throw new Error(`Too many attempts at the same page.`); | ||
| } | ||
|
|
||
| status.percent = percent; | ||
|
|
@@ -179,12 +200,16 @@ | |
| // but we are not exiting!! | ||
| } | ||
|
|
||
| function cancelDownload() { | ||
| function cancelDownload(closeThisModal) { | ||
| if (!downloadInProgress) { | ||
| console.log('-- download.cancelDownload EXITING'); | ||
| return; | ||
| } | ||
|
|
||
| if (closeThisModal) { | ||
| closeDownloadModal = true; | ||
| } | ||
|
|
||
| cancellingDownload = true; | ||
|
|
||
| let cancelUrl = new URL(`${location.protocol}//${HT.service_domain}/${action}`); | ||
|
|
@@ -284,7 +309,7 @@ | |
| errorMessage = 'Please try again. If downloads continue to fail, contact <a href="mailto:support@hathitrust.org">support@hathitrust.org</a>.'; | ||
| HT.live.announce(errorMessage.replace(/<\/?[^>]+(>|$)/g, "")); | ||
| downloadInProgress = false; | ||
| _mtm.push({'event': 'pt-large-download-error', 'downloadUrl': `${requestUrl.toString()}`}); | ||
| _mtm.push({'event': 'pt-download-error', 'errorType': 'callback script error', 'downloadUrl': `${requestUrl.toString()}`}); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the original matomo custom event error handling to be more specific to the situation it's logging. |
||
| }; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only want to hide the modal if the user clicks the Cancel button. I needed a way to send the cancel callback without closing the modal, so this I added a conditional for that here.