@@ -14,12 +14,41 @@ class FrontController implements FrontControllerInterface
14
14
*/
15
15
protected $ _routerList ;
16
16
17
+ /**
18
+ * Application state
19
+ *
20
+ * @var State
21
+ */
22
+ protected $ appState ;
23
+
24
+ /**
25
+ * Message manager
26
+ *
27
+ * @var \Magento\Framework\Message\ManagerInterface
28
+ */
29
+ protected $ messageManager ;
30
+
31
+ /**
32
+ * @var \Psr\Log\LoggerInterface
33
+ */
34
+ protected $ logger ;
35
+
17
36
/**
18
37
* @param RouterList $routerList
38
+ * @param State $appState
39
+ * @param \Magento\Framework\Message\ManagerInterface $messageManager
40
+ * @param \Psr\Log\LoggerInterface $logger
19
41
*/
20
- public function __construct (RouterList $ routerList )
21
- {
42
+ public function __construct (
43
+ RouterList $ routerList ,
44
+ State $ appState ,
45
+ \Magento \Framework \Message \ManagerInterface $ messageManager ,
46
+ \Psr \Log \LoggerInterface $ logger
47
+ ) {
22
48
$ this ->_routerList = $ routerList ;
49
+ $ this ->appState = $ appState ;
50
+ $ this ->messageManager = $ messageManager ;
51
+ $ this ->logger = $ logger ;
23
52
}
24
53
25
54
/**
@@ -50,6 +79,16 @@ public function dispatch(RequestInterface $request)
50
79
$ request ->setActionName ('noroute ' );
51
80
$ request ->setDispatched (false );
52
81
break ;
82
+ } catch (\Magento \Framework \LocalizedException $ e ) {
83
+ $ result = $ this ->handleException ($ e , $ actionInstance , $ e ->getMessage ());
84
+ break ;
85
+ } catch (\Exception $ e ) {
86
+ // @todo Message should be clarified
87
+ $ message = $ this ->appState ->getMode () == State::MODE_DEVELOPER
88
+ ? $ e ->getMessage ()
89
+ : (string )__ ('An error occurred while processing your request ' );
90
+ $ result = $ this ->handleException ($ e , $ actionInstance , $ message );
91
+ break ;
53
92
}
54
93
}
55
94
}
@@ -59,4 +98,19 @@ public function dispatch(RequestInterface $request)
59
98
}
60
99
return $ result ;
61
100
}
101
+
102
+ /**
103
+ * Handle exception
104
+ *
105
+ * @param \Exception $e
106
+ * @param \Magento\Framework\App\ActionInterface $actionInstance
107
+ * @param string $message
108
+ * @return \Magento\Framework\Controller\Result\Redirect
109
+ */
110
+ protected function handleException ($ e , $ actionInstance , $ message )
111
+ {
112
+ $ this ->messageManager ->addError ($ message );
113
+ $ this ->logger ->critical ($ e ->getMessage ());
114
+ return $ actionInstance ->getDefaultRedirect ();
115
+ }
62
116
}
0 commit comments