const fourOhFourHandler = require('./fourOhFourHandler');

/**
 * Handles compilation errors
 * like when a template or page does not exist
 * @param {object} req - Request object
 * @param {object} res - Response object
 * @param {String} type - Type of error
 * @param {String} [template] - Template that the error happened with
 */
function handleCompileErrorRoutes(req, res, type, template) {
  switch (type) {
    case 'no-html':
    case 'no-template':
    case 'no-homepage': {
      const r = type;
      const p = req.originalUrl;
      const t = template;
      return res.redirect(`/admin/error?r=${r}&p=${p}&t=${t}`);
    }
    case 'no-exist':
      return fourOhFourHandler(req, res);
    default:
      return res.send(type);
  }
}

module.exports = handleCompileErrorRoutes;

@@ -494,33 +494,43 @@
 nst 
-r =
+obj = %7B%0A        r:
  type
-;
+,
 %0A      
-const p =
+  p:
  req
@@ -545,35 +545,284 @@
 lUrl
-;%0A      const t = template;
+,%0A      %7D;%0A%0A      if (template) obj.t = template;%0A%0A      const queryString = Object.keys(obj).reduce((prev, curr, i) =%3E %7B%0A        let queryParam = %60$%7Bcurr%7D=$%7Bobj%5Bcurr%5D%7D%60;%0A        if (i !== 0) queryParam = %60&$%7BqueryParam%7D%60;%0A        return %60$%7Bprev%7D$%7BqueryParam%7D%60;%0A      %7D, '');%0A
 %0A   
@@ -862,27 +862,21 @@
 ror?
-r=$%7Br%7D&p=$%7Bp%7D&t=$%7Bt
+$%7BqueryString
 %7D%60);

Tweak error handler to prevent undefined in URL