Skip to content

Commit

Permalink
[BUGFIX] Handle Guzzle exceptions in linkvalidator
Browse files Browse the repository at this point in the history
* 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/55666
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
sypets authored and lolli42 committed Feb 12, 2018
1 parent f48414d commit 0ec020c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,22 @@ public function checkLink($url, $softRefEntry, $reference)
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();
$response = $e->getResponse();
$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';
Expand Down Expand Up @@ -133,6 +141,9 @@ public function getErrorMessage($errorParams)
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']);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<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>
Expand Down

0 comments on commit 0ec020c

Please sign in to comment.