6

Date: May 27th, 2015 (given the fast changing nature of Magento 2)

For many classes of PHP errors/exceptions in Magento 2, the default system behavior is to redirect the user to the homepage, and rely on the homepage's exception handling code to display the error.

Where does this redirect happen? Is it in a single place, or are there multiple dispatch loops where it might happen? The PHP error handler Magento sets

#File: lib/internal/Magento/Framework/App/ErrorHandler.php
public function handler($errorNo, $errorStr, $errorFile, $errorLine)
{
    if (strpos($errorStr, 'DateTimeZone::__construct') !== false) {
        // there's no way to distinguish between caught system exceptions and warnings
        return false;
    }
    $errorNo = $errorNo & error_reporting();
    if ($errorNo == 0) {
        return false;
    }
    $msg = isset($this->errorPhrases[$errorNo]) ? $this->errorPhrases[$errorNo] : "Unknown error ({$errorNo})";
    $msg .= ": {$errorStr} in {$errorFile} on line {$errorLine}";
    throw new \Exception($msg);
}

appears to turn all PHP errors into a global Exception. This means errors are caught somewhere in the execution chain and a redirect is dispatched -- I'm looking for the spot (or spots) where this catch and redirect behavior happens.

  • boss, welcome back again :) – Amit Bera May 27 '15 at 17:56
5

I suspect what you are seeing is related to how the FrontController handles errors.

Catch - FrontController calling getDefaultResult

} catch (\Exception $e) {
    $this->handleException($e);
    $result = $actionInstance->getDefaultResult();
}

Redirect - AbstractAction redirecting to base URL

public function getDefaultResult()
{
    $resultRedirect = $this->resultRedirectFactory->create();
    return $resultRedirect->setRefererOrBaseUrl();
}
  • would you happen to know where this catch now happens in Magento 2.0.0? – peedee Dec 7 '15 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.