@@ -67,7 +67,7 @@ public function dispatch(RequestInterface $request)
67
67
$ routingCycleCounter = 0 ;
68
68
$ result = null ;
69
69
while (!$ request ->isDispatched () && $ routingCycleCounter ++ < 100 ) {
70
- $ result = $ this ->matchAction ($ request );
70
+ $ result = $ this ->processRequest ($ request );
71
71
}
72
72
\Magento \Framework \Profiler::stop ('routers_match ' );
73
73
if ($ routingCycleCounter > 100 ) {
@@ -81,23 +81,27 @@ public function dispatch(RequestInterface $request)
81
81
*
82
82
* @param \Exception $e
83
83
* @param \Magento\Framework\App\ActionInterface $actionInstance
84
- * @param string $message
85
84
* @return \Magento\Framework\Controller\Result\Redirect
86
85
*/
87
- protected function handleException ($ e , $ actionInstance, $ message )
86
+ protected function handleException ($ e , $ actionInstance )
88
87
{
89
- $ this ->messageManager ->addError ($ message );
88
+ $ needToMaskDisplayMessage = !($ e instanceof \Magento \Framework \Exception \LocalizedException)
89
+ && ($ this ->appState ->getMode () != State::MODE_DEVELOPER );
90
+ $ displayMessage = $ needToMaskDisplayMessage
91
+ ? (string )new \Magento \Framework \Phrase ('An error occurred while processing your request ' )
92
+ : $ e ->getMessage ();
93
+ $ this ->messageManager ->addError ($ displayMessage );
90
94
$ this ->logger ->critical ($ e ->getMessage ());
91
95
return $ actionInstance ->getDefaultRedirect ();
92
96
}
93
97
94
98
/**
95
- * Match action, dispatch
99
+ * Route request and dispatch it
96
100
*
97
101
* @param RequestInterface $request
98
- * @return \Magento\Framework\Controller\Result\Redirect
102
+ * @return ResponseInterface| \Magento\Framework\Controller\ResultInterface|null
99
103
*/
100
- protected function matchAction (RequestInterface $ request )
104
+ protected function processRequest (RequestInterface $ request )
101
105
{
102
106
$ result = null ;
103
107
/** @var \Magento\Framework\App\RouterInterface $router */
@@ -107,24 +111,20 @@ protected function matchAction(RequestInterface $request)
107
111
if ($ actionInstance ) {
108
112
$ request ->setDispatched (true );
109
113
$ actionInstance ->getResponse ()->setNoCacheHeaders ();
110
- $ result = $ actionInstance ->dispatch ($ request );
114
+ try {
115
+ $ result = $ actionInstance ->dispatch ($ request );
116
+ } catch (Action \NotFoundException $ e ) {
117
+ throw $ e ;
118
+ } catch (\Exception $ e ) {
119
+ $ result = $ this ->handleException ($ e , $ actionInstance );
120
+ }
111
121
break ;
112
122
}
113
123
} catch (Action \NotFoundException $ e ) {
114
124
$ request ->initForward ();
115
125
$ request ->setActionName ('noroute ' );
116
126
$ request ->setDispatched (false );
117
127
break ;
118
- } catch (\Magento \Framework \Exception \LocalizedException $ e ) {
119
- $ result = $ this ->handleException ($ e , $ actionInstance , $ e ->getMessage ());
120
- break ;
121
- } catch (\Exception $ e ) {
122
- // @todo Message should be clarified
123
- $ message = $ this ->appState ->getMode () == State::MODE_DEVELOPER
124
- ? $ e ->getMessage ()
125
- : (string )new \Magento \Framework \Phrase ('An error occurred while processing your request ' );
126
- $ result = $ this ->handleException ($ e , $ actionInstance , $ message );
127
- break ;
128
128
}
129
129
}
130
130
return $ result ;
0 commit comments