Skip to content

ETT-1411: additional error handling and matomo custom events#202

Merged
carylwyatt merged 1 commit intomainfrom
ETT-1411-pt-download-errors
Apr 20, 2026
Merged

ETT-1411: additional error handling and matomo custom events#202
carylwyatt merged 1 commit intomainfrom
ETT-1411-pt-download-errors

Conversation

@carylwyatt
Copy link
Copy Markdown
Member

@carylwyatt carylwyatt commented Apr 14, 2026

There is some kind of bug causing download errors in page turner, and the error handling I recently added didn't account for all the ways imgsrv would/would not send data back about those types of errors. This PR addresses the new error states that I'm aware of now.

All of the errors we can catch in the front-end are larger/"callback"-style downloads. The small downloads are handled completely by imgsrv/the browser. All of the new error handling is related to download progress and calls to /imgsrv/download-status.

Three new scenarios I accounted for:

  1. Originally during progress checks, we were looking for a status back from imgsrv of EOT or DONE to show a message that the download is complete. I found that the DONE status is also sent back from imgsrv when "No Download Found"... which is the opposite of the download being complete. The correct DONE status is always accompanied by a current_page of -1, so I added that to the "ready for download" conditional.
  2. The response that comes back from imgsrv with the "No Download Found" message doesn't include a current_page, so I added that to a new conditional. Under these conditions, there will be an error message in the modal and a matomo error event logged.
  3. The final scenario is the one mentioned in the ticket: there was originally a conditional that looks like it checks for too many calls to imgsrv and then sets some error state... but the error state didn't actually do anything. Also the number of attempts was 100 and that's just way too many. I updated the conditional to check for 5 attempts (the attempt number goes back to 0 every time progress is updated, so this block will only be triggered if progress isn't continuing as it should. I tested 10 attempts and it was painfully long. I tried 5 attempts with several high-resolution TIFF downloads and never had an issue with timeout, so I think this is safe). After 5 attempts, it cancels the download (sends the STOP status to /imgsrv/download-status), updates the UI with an error message for the user, and logs a custom error event in matomo.

I also rearranged cancelDownload() so I could pass a boolean value for whether or not to close the modal when the download is cancelled via callback().

The matomo tags are working
Screenshot 2026-04-14 at 10 42 55 AM

testing

This is staged on dev-3. I recommend using this volume that has a error-prone first scan/seq/page to test: https://dev-3.babel.hathitrust.org/cgi/pt?id=mdp.39015082631287&seq=1

  1. Open the download panel. Whole item/PDF should be the default selection, all you have to do is press "Download".
  2. The modal should appear. The progress bar should progress by one teeny tiny sliver, then after about 10 seconds, you should see an error message.
  3. The weird part: Try to download again. You should get an error again but much quicker (this is the part where, for reasons I don't understand, imgsrv sends the response "No Download Found" with a status of "DONE").
  4. For good measure, you can also attempt a current page PDF download for seq 1 and see that it opens a new tab, downloads something, but that the download is an empty/broken file.

clearInterval(trackerInterval);
trackerInterval = null;
modal.hide();
if (closeDownloadModal) modal.hide();
Copy link
Copy Markdown
Member Author

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.

numAttempts += 1;
errorCount++;

if (progressError) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's an error with /imgsrv/download-status update the UI and clear the trackerInterval.

let percent;
let current = data.status;
if (current == 'EOT' || current == 'DONE') {
if (current == 'EOT' || (current == 'DONE' && data.current_page == -1)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 1: The real DONE status is always accompanied by a current_page of -1, so I added that to the "ready for download" conditional.

percent = 100;
downloadInProgress = false;
HT.live.announce(`All done! Your ${formatTitle[format]} is ready for download.`);
} else if (current == 'DONE' && !data.current_page) {
Copy link
Copy Markdown
Member Author

@carylwyatt carylwyatt Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scenario 2: The response that comes back from imgsrv with the "No Download Found" message doesn't include a current_page, so I added that to an additional conditional. Under these conditions, there will be an error message in the modal and a matomo error event logged.

}
if (numAttempts > 100) {
status.error = true;
if (numAttempts > 5) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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 status.error to use the new progressError conditional in the try/catch block.

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()}`});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.

@carylwyatt carylwyatt requested a review from moseshll April 15, 2026 20:52
Copy link
Copy Markdown
Contributor

@moseshll moseshll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Behavior on dev-3 exactly as described. I look forward to getting to the bottom of some of the imgsrv shenanigans. APPROVE

@carylwyatt carylwyatt merged commit 9132ec8 into main Apr 20, 2026
2 checks passed
@carylwyatt carylwyatt deleted the ETT-1411-pt-download-errors branch April 20, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants