[BUGFIX] Handle Guzzle exceptions in linkvalidator 78/55678/2
authorSybille Peters <sypets@gmx.de>
Sun, 11 Feb 2018 18:10:10 +0000 (19:10 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 12 Feb 2018 13:05:49 +0000 (14:05 +0100)
* The Guzzle exceptions are handled in order to produce better,
  localized error messages in the Report
* Add a new language key for "Network error"

Resolves: #83611
Releases: master, 8.7
Change-Id: I6480c349cbc3325315f25187df56a4914922e463
Reviewed-on: https://review.typo3.org/55678
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php
typo3/sysext/linkvalidator/Resources/Private/Language/Module/locallang.xlf

index 22a2fe5..4709835 100644 (file)
@@ -83,7 +83,7 @@ class ExternalLinktype extends AbstractLinktype
             if ($response->getStatusCode() >= 300) {
                 $isValidUrl = false;
                 $errorParams['errorType'] = $response->getStatusCode();
             if ($response->getStatusCode() >= 300) {
                 $isValidUrl = false;
                 $errorParams['errorType'] = $response->getStatusCode();
-                $errorParams['message'] = $response->getReasonPhrase();
+                $errorParams['message'] = $this->getErrorMessage($errorParams);
             }
         } catch (TooManyRedirectsException $e) {
             $lastRequest = $e->getRequest();
             }
         } catch (TooManyRedirectsException $e) {
             $lastRequest = $e->getRequest();
@@ -91,6 +91,14 @@ class ExternalLinktype extends AbstractLinktype
             $errorParams['errorType'] = 'loop';
             $errorParams['location'] = (string)$lastRequest->getUri();
             $errorParams['errorCode'] = $response->getStatusCode();
             $errorParams['errorType'] = 'loop';
             $errorParams['location'] = (string)$lastRequest->getUri();
             $errorParams['errorCode'] = $response->getStatusCode();
+        } catch (\GuzzleHttp\Exception\ClientException $e) {
+            $isValidUrl = false;
+            $errorParams['errorType'] = $e->getResponse()->getStatusCode();
+            $errorParams['message'] = $this->getErrorMessage($errorParams);
+        } catch (\GuzzleHttp\Exception\RequestException $e) {
+            $isValidUrl = false;
+            $errorParams['errorType'] = 'network';
+            $errorParams['message'] = $this->getErrorMessage($errorParams);
         } catch (\Exception $e) {
             $isValidUrl = false;
             $errorParams['errorType'] = 'exception';
         } catch (\Exception $e) {
             $isValidUrl = false;
             $errorParams['errorType'] = 'exception';
@@ -133,6 +141,9 @@ class ExternalLinktype extends AbstractLinktype
             case 'exception':
                 $response = sprintf($lang->getLL('list.report.httpexception'), $errorParams['message']);
                 break;
             case 'exception':
                 $response = sprintf($lang->getLL('list.report.httpexception'), $errorParams['message']);
                 break;
+            case 'network':
+                $response = $lang->getLL('list.report.networkexception');
+                break;
             default:
                 $response = sprintf($lang->getLL('list.report.otherhttpcode'), $errorType, $errorParams['message']);
         }
             default:
                 $response = sprintf($lang->getLL('list.report.otherhttpcode'), $errorType, $errorParams['message']);
         }
index b449bcd..e9c7cbe 100644 (file)
                        <trans-unit id="list.report.httpexception">
                                <source>Exception: %s</source>
                        </trans-unit>
                        <trans-unit id="list.report.httpexception">
                                <source>Exception: %s</source>
                        </trans-unit>
+                       <trans-unit id="list.report.networkexception">
+                               <source>Network error</source>
+                       </trans-unit>
                        <trans-unit id="list.msg.ok">
                                <source>Ok</source>
                        </trans-unit>
                        <trans-unit id="list.msg.ok">
                                <source>Ok</source>
                        </trans-unit>