• MODx Parse Error redirect#

  • jadietrich Reply #1, 4 months, 3 weeks ago

    Reply
    I've searched around and haven't seen a way to redirect MODx parse errors to a simple page not found page.

    Does anyone know a way to do this?

    Thanks in advance for any assistance.


  • Everett Reply #2, 4 months, 3 weeks ago

    Reply
    What exactly do you mean? You mean you want to pre-emptively detect parse errors and redirect the user if errors were detected?

    I haven't heard of that type of thing...

    What version of MODX are you using?


  • jadietrich Reply #3, 4 months, 3 weeks ago

    Reply
    I'm using Evolution 1.0.2

    Yes in order to create a more streamlined experience for users, and increase security by not displaying any information a hacker could use. I'd like to redirect any parse error to a page not found for my production environment.

    Could a plugin be used to accomplish such a thing? Something like this:

    if ($modx->event->name == 'OnPageNotFound') {
         $errorPage = $modx->getOption('pnf.page');
         if (empty($errorPage)) {
             $modx->sendErrorPage();
         } else {
             $mailto = $modx->getOption('pnf.mailto');
             if (!empty($mailto)) {
                // send a message to a local account
                $resourceId = $modx->resource->get('id');
                $subject = 'Page not found';
                $body = 'Someone tried to access document id '.$resourceId;
                $modx->getService('mail', 'mail.modPHPMailer');
                $modx->mail->set(modMail::MAIL_BODY, $body);
                $modx->mail->set(modMail::MAIL_FROM, '$modx->getOption('pnf.mailfrom'));
                $modx->mail->set(modMail::MAIL_FROM_NAME, 'MODx');
                $modx->mail->set(modMail::MAIL_SENDER, 'MODx');
                $modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                $modx->mail->address('to',$mailto);
                $modx->mail->setHTML(true);
                $modx->mail->send();
             }
             $url = $this->makeUrl($scriptProperties['page']);
             $modx->sendRedirect($url, 1);
             exit;
        }
    }


    Except instead of triggering when the page isn't found (OnPageNotFound) trigger whenever a parse error is detected.


  • Everett Reply #4, 4 months, 3 weeks ago

    Reply
    I don't think there's an "onParserError" event... and you should probably upgrade to 1.0.5. You may have to do something hacky, but that is a problem in Evo.


  • breezer Reply #5, 4 months, 3 weeks ago

    Reply
    You should definately upgrade to evolution 1.0.5. Although there isn't any way of redirecting on a parse error, the 1.0.5 version just shows a blank page to visitors on the frontend if an error occurs. If you are logged into the manager and view the errored page, a printout describing the error issue is shown.


  • BobRay Reply #6, 4 months, 3 weeks ago

    Reply
    What, exactly, do you mean by a parse error? Your code suggests that you just mean a page-not-found event. If so, you can designate any page as the error page and put a snippet on it that does whatever you want.

    You might also look at the LogPageNotFound package for Revolution. I think it could be adapted to work in Evolution.


  • Everett Reply #7, 4 months, 3 weeks ago

    Reply
    I believe the OP is referring to Evo's noisome habit of displaying juicy system info when the parser hits a snag.


  • jadietrich Reply #8, 4 months, 3 weeks ago

    Reply
    This is great information guys! I'll be upgrading to 1.0.5

    Yes I've been referring to Evo's noisome habit of displaying juicy system information, and although a blank page isn't exactly what I've been looking for it is preferable to what 1.0.2 is doing.

    I really wish there was an "onParseError" event as it would be very useful and not too difficult to implement.


  • Everett Reply #9, 4 months, 3 weeks ago

    Reply
    It's already a feature request: http://bugs.modx.com/issues/1985


  • jadietrich Reply #10, 4 months, 1 week ago

    Reply
    I've upgraded my Evo install to 1.0.5 in my local environment. However I am still getting the noisome « MODx Parse Error » displayed to the user when the parser encounters a problem.

    Any other suggestions on how I can get rid of these client displayed parse errors?