99
1010use Magento \AdminAdobeIms \Model \ImsConnection ;
1111use Magento \Framework \Exception \InvalidArgumentException ;
12+ use Magento \Framework \Message \ManagerInterface as MessageManagerInterface ;
1213use Magento \Framework \View \Element \Block \ArgumentInterface ;
14+ use Psr \Log \LoggerInterface ;
1315
1416class LinkViewModel implements ArgumentInterface
1517{
16- /** @var string */
17- private string $ authUrl ;
18+ /**
19+ * @var string|null
20+ */
21+ private ?string $ authUrl ;
22+
23+ /**
24+ * @var LoggerInterface
25+ */
26+ private LoggerInterface $ logger ;
27+
28+ /**
29+ * @var MessageManagerInterface
30+ */
31+ private MessageManagerInterface $ messageManager ;
1832
1933 /**
2034 * @param ImsConnection $connection
35+ * @param LoggerInterface $logger
36+ * @param MessageManagerInterface $messageManager
2137 */
2238 public function __construct (
23- ImsConnection $ connection
39+ ImsConnection $ connection ,
40+ LoggerInterface $ logger ,
41+ MessageManagerInterface $ messageManager
2442 ) {
43+ $ this ->logger = $ logger ;
44+ $ this ->messageManager = $ messageManager ;
45+
2546 try {
2647 $ this ->authUrl = $ connection ->auth ();
27- } catch (InvalidArgumentException $ exception ) {
28- $ this ->authUrl = '' ;
48+ } catch (InvalidArgumentException $ e ) {
49+ $ this ->logger ->error ($ e ->getMessage ());
50+ $ this ->authUrl = null ;
51+ $ this ->addImsErrorMessage (
52+ 'Could not connect to Adobe IMS. ' ,
53+ $ e ->getMessage ()
54+ );
55+ } catch (\Exception $ e ) {
56+ $ this ->logger ->error ($ e ->getMessage ());
57+ $ this ->authUrl = null ;
58+ $ this ->addImsErrorMessage (
59+ 'Could not connect to Adobe IMS. ' ,
60+ 'Something went wrong during Adobe IMS connection check. '
61+ );
2962 }
3063 }
3164
@@ -42,10 +75,28 @@ public function isActive(): bool
4275 /**
4376 * Get authorization URL for Login Button
4477 *
45- * @return string
78+ * @return string|null
4679 */
47- public function getButtonLink (): string
80+ public function getButtonLink (): ? string
4881 {
4982 return $ this ->authUrl ;
5083 }
84+
85+ /**
86+ * Add Admin Adobe IMS Error Message
87+ *
88+ * @param string $headline
89+ * @param string $message
90+ * @return void
91+ */
92+ private function addImsErrorMessage (string $ headline , string $ message ): void
93+ {
94+ $ this ->messageManager ->addComplexErrorMessage (
95+ 'adminAdobeImsMessage ' ,
96+ [
97+ 'headline ' => __ ($ headline )->getText (),
98+ 'message ' => __ ($ message )->getText ()
99+ ]
100+ );
101+ }
51102}
0 commit comments