errorPage.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. let errorWrittenToPage = false;
  2. document.addEventListener("DOMContentLoaded", function() {
  3. setTimeout(function() {
  4. if(errorWrittenToPage != true)
  5. setErrorDisp(500, "Internal Server Error", "Error while finding the error message - oh the irony");
  6. }, 5000);
  7. try
  8. {
  9. let errorInfo = JSON.parse(atob(Cookies.get("errorInfo"))); // eslint-disable-line no-undef
  10. let statusCode = Number(errorInfo ? errorInfo.code : NaN);
  11. if(isNaN(statusCode))
  12. statusCode = 500;
  13. let errorReasonMsg = "";
  14. let errorSubtext = "";
  15. switch(statusCode)
  16. {
  17. case 404:
  18. errorReasonMsg = "Not Found";
  19. errorSubtext = "<!--%#INSERT:NAME#%--> couldn't find a resource that corresponds to the URL you have entered.<br>Please make sure the URL is correct or <a href=\"<!--%#INSERT:DOCSURL#%-->\">visit the documentation by clicking here</a>.";
  20. break;
  21. case 429:
  22. errorReasonMsg = "Too Many Requests";
  23. errorSubtext = "You have sent too many requests to the server in a short amount of time.<br>Please wait a few minutes and try again.";
  24. break;
  25. case 500: default:
  26. errorReasonMsg = "Internal Server Error";
  27. errorSubtext = "<!--%#INSERT:NAME#%--> encountered an unexpected internal error.<br>If this error persists and error details were provided on this page, please <a href=\"<!--%#INSERT:AUTHORWEBSITEURL#%-->\">contact me</a> with the error details and I will try to fix it and/or help you.<br>Alternatively, <a href=\"<!--%#INSERT:DOCSURL#%-->\">visit the documentation by clicking here</a>.";
  28. break;
  29. }
  30. setErrorDisp(statusCode, errorReasonMsg, errorInfo.message, errorSubtext);
  31. }
  32. catch(err)
  33. {
  34. setErrorDisp(500, "Internal Server Error", "Error while finding the error message - oh the irony");
  35. }
  36. });
  37. /**
  38. * Sets the error display of the page
  39. * @param {Number} code
  40. * @param {String} summary
  41. * @param {String} details
  42. * @param {String} subText
  43. */
  44. function setErrorDisp(code = 500, summary = "Internal Server Error", details = "No details provided", subText = "")
  45. {
  46. errorWrittenToPage = true;
  47. document.title = ("<!--%#INSERT:NAME#%--> - Error " + code.toString());
  48. document.getElementById("errCodeDisplay").innerText = (code.toString() + " - " + summary);
  49. document.getElementById("errDetailDisplay").innerText = "Details: " + details;
  50. if(subText)
  51. document.getElementById("errSubText").innerText = subText;
  52. }