Skip to content

Commit

Permalink
Fixed exception for Bad Connections
Browse files Browse the repository at this point in the history
  • Loading branch information
byjg committed Apr 15, 2016
1 parent 9d9ee0a commit 0a9ee48
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ install:
- composer install

script:
- cd tests
- phpunit --bootstrap bootstrap.php .
- phpunit

9 changes: 7 additions & 2 deletions SparQL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SparQL;

use ByJG\Util\CurlException;
use ByJG\Util\WebRequest;
use SparQL\Exception;

Expand Down Expand Up @@ -89,10 +90,14 @@ public function dispatchQuery($sparql, $timeout = null)
$webRequest->setCurlOption(CURLOPT_TIMEOUT_MS, $timeout);
}

$output = $webRequest->get();
try {
$output = $webRequest->get();
} catch (CurlException $ex) {
throw new ConnectionException($ex->getMessage());
}

if ($output === '') {
throw new Exception('URL returned no data', -1);
throw new ConnectionException('URL returned no data', -1);
}
if ($webRequest->getLastStatus() != 200) {
throw new Exception(
Expand Down
8 changes: 8 additions & 0 deletions SparQL/ConnectionException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace SparQL;

class ConnectionException extends \Exception
{
//put your code here
}
2 changes: 1 addition & 1 deletion tests/SparQL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testGetOk()
}

/**
* @expectedException \ByJG\Util\CurlException
* @expectedException \SparQL\ConnectionException
*/
function test_wrongSparQLDataset()
{
Expand Down
3 changes: 0 additions & 3 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit 0a9ee48

Please sign in to comment.