PennController for IBEX › Forums › Requests › Prevent participants from continuing if resources weren't downloaded › Reply To: Prevent participants from continuing if resources weren't downloaded
Hi Irene,
If you experience issues with preloading zip files, I suggest you try using PennController 2.1 beta, on which I am still currently working, where I revise the way zip files are downloaded
Then if you still need to detect failure to download the zip file, you could add a file named AA.js to your Modules folder (you want the filename to come before PennController.js in an alphanumeric order) with a content like this:
const zipError = ()=>{ const pe = document.querySelector(".PennController-PennController"); const parent = pe.parentElement; pe.remove(); const warning = document.createElement("P"); warning.innerHTML = "There was a problem loading resources for this experiment. Please reload this page to try again."; parent.append(warning); }; const oldFetch = window.fetch; window.fetch = function(...args){ const r = oldFetch.apply(this, args); if (typeof(args[0])=="string" && args[0].match(/\.zip$/i)) r.catch(zipError); return r; }
And to fully capture all the errors in the download process, also add this at the top of your project’s main.js script:
PennController._AddElementType("dummyelementname", function(PennEngine) { const olderror = PennEngine.debug.error; PennEngine.debug.error = function(...args) { if (typeof(args[0])=="string" && args[0].match(/Error downloading .+zip/)) zipError(); return olderror.apply(this, args); } })
Let me know if you have questions
Jeremy