Skip to content

Commit

Permalink
cleaned up exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Feb 18, 2013
1 parent fc66793 commit 790ff91
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions lib/Buzz/Client/AbstractCurl.php
Expand Up @@ -6,7 +6,7 @@
use Buzz\Message\Form\FormUploadInterface;
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
use Buzz\Exception\TransmissionException;
use Buzz\Exception\ClientException;

/**
* Base client class with helpers for working with cURL.
Expand All @@ -25,7 +25,7 @@ abstract class AbstractCurl extends AbstractClient
static protected function createCurlHandle()
{
if (false === $curl = curl_init()) {
throw new TransmissionException('Unable to create a new cURL handle');
throw new ClientException('Unable to create a new cURL handle');
}

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
Expand Down
4 changes: 2 additions & 2 deletions lib/Buzz/Client/Curl.php
Expand Up @@ -4,7 +4,7 @@

use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
use Buzz\Exception\TransmissionException;
use Buzz\Exception\ClientException;
use Buzz\Exception\LogicException;

class Curl extends AbstractCurl implements ClientInterface
Expand All @@ -26,7 +26,7 @@ public function send(RequestInterface $request, MessageInterface $response, arra
$errorMsg = curl_error($this->lastCurl);
$errorNo = curl_errno($this->lastCurl);

throw new TransmissionException($errorMsg, $errorNo);
throw new ClientException($errorMsg, $errorNo);
}

static::populateResponse($this->lastCurl, $data, $response);
Expand Down
6 changes: 3 additions & 3 deletions lib/Buzz/Client/FileGetContents.php
Expand Up @@ -5,7 +5,7 @@
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
use Buzz\Util\CookieJar;
use Buzz\Exception\TransmissionException;
use Buzz\Exception\ClientException;

class FileGetContents extends AbstractStream implements ClientInterface
{
Expand All @@ -31,7 +31,7 @@ public function getCookieJar()
/**
* @see ClientInterface
*
* @throws TransmissionException If file_get_contents() fires an error
* @throws ClientException If file_get_contents() fires an error
*/
public function send(RequestInterface $request, MessageInterface $response)
{
Expand All @@ -48,7 +48,7 @@ public function send(RequestInterface $request, MessageInterface $response)
error_reporting($level);
if (false === $content) {
$error = error_get_last();
throw new TransmissionException($error['message']);
throw new ClientException($error['message']);
}

$response->setHeaders($this->filterHeaders((array) $http_response_header));
Expand Down
10 changes: 10 additions & 0 deletions lib/Buzz/Exception/ClientException.php
@@ -0,0 +1,10 @@
<?php

namespace Buzz\Exception;

/**
* Thrown whenever a client process fails.
*/
class ClientException extends RuntimeException
{
}
@@ -1,9 +1,10 @@
<?php

namespace Buzz\Exception;

/**
* Marker interface to denote exceptions thrown from the Buzz context
* Marker interface to denote exceptions thrown from the Buzz context.
*/
interface BuzzException
interface ExceptionInterface
{
}
6 changes: 3 additions & 3 deletions lib/Buzz/Exception/InvalidArgumentException.php
Expand Up @@ -3,8 +3,8 @@
namespace Buzz\Exception;

/**
* Thrown when an invalid argument is provided
* Thrown when an invalid argument is provided.
*/
class InvalidArgumentException extends \InvalidArgumentException implements BuzzException
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
}
6 changes: 3 additions & 3 deletions lib/Buzz/Exception/LogicException.php
Expand Up @@ -3,8 +3,8 @@
namespace Buzz\Exception;

/**
* Thrown whenever a required call-flow is not respected
* Thrown whenever a required call-flow is not respected.
*/
class LogicException extends \LogicException implements BuzzException
class LogicException extends \LogicException implements ExceptionInterface
{
}
}
7 changes: 7 additions & 0 deletions lib/Buzz/Exception/RuntimeException.php
@@ -0,0 +1,7 @@
<?php

namespace Buzz\Exception;

class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
10 changes: 0 additions & 10 deletions lib/Buzz/Exception/TransmissionException.php

This file was deleted.

2 changes: 1 addition & 1 deletion test/Buzz/Test/Client/FileGetContentsTest.php
Expand Up @@ -12,7 +12,7 @@ class FileGetContentsTest extends \PHPUnit_Framework_TestCase
*/
public function testSendToInvalidUrl($host)
{
$this->setExpectedException('Buzz\Exception\TransmissionException');
$this->setExpectedException('Buzz\Exception\ClientException');

$request = new Message\Request();
$request->fromUrl('http://'.$host.':12345');
Expand Down

2 comments on commit 790ff91

@stloyd
Copy link
Contributor

@stloyd stloyd commented on 790ff91 Feb 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh... #86

@kriswallsmith
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stloyd rebase?

Please sign in to comment.