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.

1
  • boss, welcome back again :)
    – Amit Bera
    May 27, 2015 at 17:56

1 Answer 1

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();
}
1
  • would you happen to know where this catch now happens in Magento 2.0.0?
    – peedee
    Dec 7, 2015 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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