Renamed DeserializeException to HydrationException (#317)

This commit is contained in:
Tobias Nyholm 2017-03-26 17:27:47 +02:00 committed by GitHub
parent 70d467955a
commit bc5215090d
4 changed files with 10 additions and 7 deletions

View File

@ -11,6 +11,6 @@ namespace Mailgun\Exception;
use Mailgun\Exception; use Mailgun\Exception;
final class DeserializeException extends \RuntimeException implements Exception final class HydrationException extends \RuntimeException implements Exception
{ {
} }

View File

@ -9,7 +9,7 @@
namespace Mailgun\Hydrator; namespace Mailgun\Hydrator;
use Mailgun\Exception\DeserializeException; use Mailgun\Exception\HydrationException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
/** /**
@ -29,12 +29,12 @@ final class ArrayHydrator implements Hydrator
{ {
$body = $response->getBody()->__toString(); $body = $response->getBody()->__toString();
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) { if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
throw new DeserializeException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type')); throw new HydrationException('The ArrayHydrator cannot hydrate response with Content-Type:'.$response->getHeaderLine('Content-Type'));
} }
$content = json_decode($body, true); $content = json_decode($body, true);
if (JSON_ERROR_NONE !== json_last_error()) { if (JSON_ERROR_NONE !== json_last_error()) {
throw new DeserializeException(sprintf('Error (%d) when trying to json_decode response', json_last_error())); throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
} }
return $content; return $content;

View File

@ -9,6 +9,7 @@
namespace Mailgun\Hydrator; namespace Mailgun\Hydrator;
use Mailgun\Exception\HydrationException;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
/** /**
@ -21,6 +22,8 @@ interface Hydrator
* @param string $class * @param string $class
* *
* @return mixed * @return mixed
*
* @throws HydrationException
*/ */
public function hydrate(ResponseInterface $response, $class); public function hydrate(ResponseInterface $response, $class);
} }

View File

@ -9,7 +9,7 @@
namespace Mailgun\Hydrator; namespace Mailgun\Hydrator;
use Mailgun\Exception\DeserializeException; use Mailgun\Exception\HydrationException;
use Mailgun\Model\ApiResponse; use Mailgun\Model\ApiResponse;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
@ -31,12 +31,12 @@ final class ModelHydrator implements Hydrator
$body = $response->getBody()->__toString(); $body = $response->getBody()->__toString();
$contentType = $response->getHeaderLine('Content-Type'); $contentType = $response->getHeaderLine('Content-Type');
if (strpos($contentType, 'application/json') !== 0 && strpos($contentType, 'application/octet-stream') !== 0) { if (strpos($contentType, 'application/json') !== 0 && strpos($contentType, 'application/octet-stream') !== 0) {
throw new DeserializeException('The ModelHydrator cannot hydrate response with Content-Type: '.$contentType); throw new HydrationException('The ModelHydrator cannot hydrate response with Content-Type: '.$contentType);
} }
$data = json_decode($body, true); $data = json_decode($body, true);
if (JSON_ERROR_NONE !== json_last_error()) { if (JSON_ERROR_NONE !== json_last_error()) {
throw new DeserializeException(sprintf('Error (%d) when trying to json_decode response', json_last_error())); throw new HydrationException(sprintf('Error (%d) when trying to json_decode response', json_last_error()));
} }
if (is_subclass_of($class, ApiResponse::class)) { if (is_subclass_of($class, ApiResponse::class)) {