@@ -38,7 +38,6 @@ protected function run(array $params = []): ?string
3838 $ news = $ this ->getNews ();
3939
4040 try {
41-
4241 if (isset ($ news ['information ' ])) {
4342 $ currentItem = $ news ['information ' ];
4443 } else {
@@ -52,12 +51,12 @@ protected function run(array $params = []): ?string
5251 'datechanged ' => $ currentItem ['modifiedAt ' ],
5352 'datefetched ' => date ('Y-m-d H:i:s ' ),
5453 ];
55- } catch (\Exception $ e ) {
54+ } catch (\Throwable $ e ) {
5655 $ context = [
5756 'type ' => 'error ' ,
5857 'title ' => 'Unable to fetch news! ' ,
5958 'link ' => '' ,
60- 'news ' => " <p>Invalid JSON feed returned by <code> " . $ this ->source . " </code></p><small> " . $ e ->getMessage () . " </small> " ,
59+ 'news ' => ' <p>Invalid JSON feed returned by <code> ' . $ this ->source . ' </code></p><small> ' . $ e ->getMessage () . ' </small> ' ,
6160 ];
6261 }
6362
@@ -74,16 +73,15 @@ private function getNews(): array
7473 try {
7574 $ client = HttpClient::create ();
7675 $ fetchedNewsData = $ client ->request ('GET ' , $ this ->source , $ options )->getContent ();
77- } catch (\Exception $ e ) {
78-
76+ } catch (\Throwable $ e ) {
7977 $ message = Str::shyphenate (preg_replace ('/hash=[a-z0-9\%]+/i ' , '' , $ e ->getMessage ()));
8078
8179 return [
8280 'error ' => [
8381 'type ' => 'error ' ,
8482 'fieldValues ' => [
8583 'title ' => 'Unable to fetch news! ' ,
86- 'content ' => " <p>Unable to connect to " . $ this ->source . " </p><small> " . $ message . " </small> " ,
84+ 'content ' => ' <p>Unable to connect to ' . $ this ->source . ' </p><small> ' . $ message . ' </small> ' ,
8785 'link ' => null ,
8886 ],
8987 'modifiedAt ' => '0000-01-01 00:00:00 ' ,
@@ -120,7 +118,7 @@ private function getNews(): array
120118 'type ' => 'error ' ,
121119 'fieldValues ' => [
122120 'title ' => 'Unable to fetch news! ' ,
123- 'content ' => " <p>Unable to parse JSON from " . $ this ->source . " </p> " ,
121+ 'content ' => ' <p>Unable to parse JSON from ' . $ this ->source . ' </p> ' ,
124122 'link ' => null ,
125123 ],
126124 'modifiedAt ' => '0000-01-01 00:00:00 ' ,
@@ -137,7 +135,7 @@ private function fetchNewsOptions(): array
137135 $ db = new \Bolt \Doctrine \Version ($ conn );
138136 $ config = $ this ->getExtension ()->getBoltConfig ();
139137
140- $ options = [
138+ $ parameters = [
141139 'v ' => Version::VERSION ,
142140 'php ' => PHP_VERSION ,
143141 'db_driver ' => $ db ->getPlatform ()['driver_name ' ],
@@ -147,11 +145,12 @@ private function fetchNewsOptions(): array
147145 'env ' => $ this ->getExtension ()->getContainer ()->getParameter ('kernel.environment ' ),
148146 ];
149147
150- return [
151- 'query ' => [
152- 'hash ' => base64_encode (serialize ($ options )),
153- ],
154- 'timeout ' => 10 ,
148+ $ curlOptions = $ config ->get ('general/curl_options ' , [])->all ();
149+ $ curlOptions ['timeout ' ] = 6 ;
150+ $ curlOptions ['query ' ] = [
151+ 'hash ' => base64_encode (serialize ($ parameters )),
155152 ];
153+
154+ return $ curlOptions ;
156155 }
157156}
0 commit comments