Skip to content
Browse files

Fixes #17, returns false during unable to connect errors when validat…

…ing an API URL.
  • Loading branch information...
1 parent 4db3222 commit f4119b9ce5ae2f3a885d583e5d19850e08fe50c0 Jim Safley committed May 25, 2011
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/Scripto/Service/MediaWiki.php
View
17 lib/Scripto/Service/MediaWiki.php
@@ -640,12 +640,17 @@ static public function isValidApiUrl($apiUrl)
return false;
}
- // Ping the API endpoint for a valid response.
- $body = self::getHttpClient()->setUri($apiUrl)
- ->setParameterPost('action', 'query')
- ->setParameterPost('meta', 'siteinfo')
- ->setParameterPost('format', 'json')
- ->request('POST')->getBody();
+ try {
+ // Ping the API endpoint for a valid response.
+ $body = self::getHttpClient()->setUri($apiUrl)
+ ->setParameterPost('action', 'query')
+ ->setParameterPost('meta', 'siteinfo')
+ ->setParameterPost('format', 'json')
+ ->request('POST')->getBody();
+ // Prevent "Unable to Connect" errors.
+ } catch (Zend_Http_Client_Exception $e) {
+ return false;
+ }
self::getHttpClient()->resetParameters(true);
$response = json_decode($body, true);

0 comments on commit f4119b9

Please sign in to comment.
Something went wrong with that request. Please try again.