errorPage.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. window.errorWrittenToPage = false;
  2. document.addEventListener("DOMContentLoaded", function() {
  3. setTimeout(function() {
  4. if(window.errorWrittenToPage != true)
  5. {
  6. setErrorDisp(500, "Internal Server Error", "Error while finding the error message - oh the irony");
  7. }
  8. }, 6000);
  9. try
  10. {
  11. let errorInfo = JSON.parse(Cookies.get("errorInfo")); // eslint-disable-line no-undef
  12. let statusCode = parseInt(errorInfo["API-Error-StatusCode"]);
  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 500: default:
  22. errorReasonMsg = "Internal Server Error";
  23. 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>.";
  24. break;
  25. }
  26. setErrorDisp(parseInt(statusCode), errorReasonMsg, errorInfo["API-Error-Message"], errorSubtext);
  27. }
  28. catch(err)
  29. {
  30. setErrorDisp(500, "Internal Server Error", "Error while finding the error message - oh the irony");
  31. }
  32. });
  33. /**
  34. * Sets the error display of the page
  35. * @param {Number} code
  36. * @param {String} summary
  37. * @param {String} details
  38. * @param {String} subText
  39. */
  40. function setErrorDisp(code = 500, summary = "Internal Server Error", details = "No details provided", subText = "")
  41. {
  42. window.errorWrittenToPage = true;
  43. document.title = ("<!--%#INSERT:NAME#%--> - Error " + code.toString());
  44. document.getElementById("errCodeDisplay").innerHTML = (code.toString() + " - " + summary);
  45. document.getElementById("errDetailDisplay").innerHTML = "Details: " + details;
  46. if(subText)
  47. document.getElementById("errSubText").innerHTML = subText;
  48. }