Catch NoHttpResponseException when using HTTPClient

This commit is contained in:
Mikael Nordfeldth 2016-01-13 14:17:49 +01:00
parent 3ed632decf
commit 99da1ebe41
8 changed files with 15 additions and 20 deletions

View File

@ -27,12 +27,7 @@
* @link http://status.net/ * @link http://status.net/
*/ */
if (!defined('GNUSOCIAL')) { if (!defined('GNUSOCIAL')) { exit(1); }
exit(1);
}
require_once 'HTTP/Request2.php';
require_once 'HTTP/Request2/Response.php';
/** /**
* Useful structure for HTTP responses * Useful structure for HTTP responses
@ -332,7 +327,7 @@ class HTTPClient extends HTTP_Request2
do { do {
try { try {
$response = parent::send(); $response = parent::send();
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
$this->log(LOG_ERR, $e->getMessage()); $this->log(LOG_ERR, $e->getMessage());
throw $e; throw $e;
} }
@ -355,6 +350,8 @@ class HTTPClient extends HTTP_Request2
continue; continue;
} catch (HTTP_Request2_Exception $e) { } catch (HTTP_Request2_Exception $e) {
common_log(LOG_ERR, __CLASS__ . ": Invalid $code redirect from $url to $target"); common_log(LOG_ERR, __CLASS__ . ": Invalid $code redirect from $url to $target");
} catch (NoHttpResponseException $e) {
common_log(LOG_ERR, __CLASS__ . ": {$e->getMessage()}");
} }
} else { } else {
$reason = $response->getReasonPhrase(); $reason = $response->getReasonPhrase();

View File

@ -240,7 +240,7 @@ class DiasporaPlugin extends Plugin
$client = new HTTPClient(); $client = new HTTPClient();
$client->setBody('xml=' . Magicsig::base64_url_encode($envxml)); $client->setBody('xml=' . Magicsig::base64_url_encode($envxml));
$response = $client->post($endpoint_uri, $headers); $response = $client->post($endpoint_uri, $headers);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, "Diaspora-flavoured Salmon post to $endpoint_uri failed: " . $e->getMessage()); common_log(LOG_ERR, "Diaspora-flavoured Salmon post to $endpoint_uri failed: " . $e->getMessage());
return false; return false;
} }

View File

@ -107,7 +107,7 @@ class GeoURLPlugin extends Plugin
$request->post($this->ping, $request->post($this->ping,
null, null,
array('p' => $url)); array('p' => $url));
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_WARNING, common_log(LOG_WARNING,
"GeoURL.org ping failed for '$url' ($this->ping)"); "GeoURL.org ping failed for '$url' ($this->ping)");
} }

View File

@ -182,9 +182,8 @@ class LinkbackPlugin extends Plugin
common_log(LOG_WARNING, common_log(LOG_WARNING,
"Webmention request failed for '$url' ($endpoint)"); "Webmention request failed for '$url' ($endpoint)");
} }
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_WARNING, common_log(LOG_WARNING, "Webmention request failed for '{$url}' ({$endpoint}): {$e->getMessage()}");
"Webmention request failed for '$url' ($endpoint)");
} }
} }
@ -224,9 +223,8 @@ class LinkbackPlugin extends Plugin
"Pingback success for '$url' ($endpoint): ". "Pingback success for '$url' ($endpoint): ".
"'$response'"); "'$response'");
} }
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_WARNING, common_log(LOG_WARNING, "Pingback request failed for '{$url}' ({$endpoint}): {$e->getMessage()}");
"Pingback request failed for '$url' ($endpoint)");
} }
} }

View File

@ -1404,7 +1404,7 @@ class OStatusPlugin extends Plugin
$client = new HTTPClient(); $client = new HTTPClient();
$client->setBody($envxml); $client->setBody($envxml);
$response = $client->post($endpoint_uri, $headers); $response = $client->post($endpoint_uri, $headers);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage()); common_log(LOG_ERR, "Salmon post to $endpoint_uri failed: " . $e->getMessage());
return false; return false;
} }

View File

@ -118,7 +118,7 @@ class FeedDiscovery
try { try {
$client = new HTTPClient(); $client = new HTTPClient();
$response = $client->get($url); $response = $client->get($url);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, __METHOD__ . " Failure for $url - " . $e->getMessage()); common_log(LOG_ERR, __METHOD__ . " Failure for $url - " . $e->getMessage());
throw new FeedSubBadURLException($e->getMessage()); throw new FeedSubBadURLException($e->getMessage());
} }

View File

@ -63,7 +63,7 @@ class RSSCloudNotifier
try { try {
$client = new HTTPClient(); $client = new HTTPClient();
$response = $client->get($url); $response = $client->get($url);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_INFO, common_log(LOG_INFO,
'RSSCloud plugin - failure testing notify handler ' . 'RSSCloud plugin - failure testing notify handler ' .
$endpoint . ' - ' . $e->getMessage()); $endpoint . ' - ' . $e->getMessage());
@ -118,7 +118,7 @@ class RSSCloudNotifier
try { try {
$client = new HTTPClient(); $client = new HTTPClient();
$response = $client->post($endpoint, $headers, $postdata); $response = $client->post($endpoint, $headers, $postdata);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' . common_log(LOG_INFO, 'RSSCloud plugin - failure notifying ' .
$endpoint . ' that feed ' . $feed . $endpoint . ' that feed ' . $feed .
' has changed: ' . $e->getMessage()); ' has changed: ' . $e->getMessage());

View File

@ -108,7 +108,7 @@ function getTweetHtml($url)
try { try {
$client = new HTTPClient(); $client = new HTTPClient();
$response = $client->get($url); $response = $client->get($url);
} catch (HTTP_Request2_Exception $e) { } catch (Exception $e) {
print "ERROR: HTTP response " . $e->getMessage() . "\n"; print "ERROR: HTTP response " . $e->getMessage() . "\n";
return false; return false;
} }