mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-26 06:46:08 +03:00
Renamed DeserializeException to HydrationException (#317)
This commit is contained in:
parent
70d467955a
commit
bc5215090d
@ -11,6 +11,6 @@ namespace Mailgun\Exception;
|
||||
|
||||
use Mailgun\Exception;
|
||||
|
||||
final class DeserializeException extends \RuntimeException implements Exception
|
||||
final class HydrationException extends \RuntimeException implements Exception
|
||||
{
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Mailgun\Hydrator;
|
||||
|
||||
use Mailgun\Exception\DeserializeException;
|
||||
use Mailgun\Exception\HydrationException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
@ -29,12 +29,12 @@ final class ArrayHydrator implements Hydrator
|
||||
{
|
||||
$body = $response->getBody()->__toString();
|
||||
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);
|
||||
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;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
namespace Mailgun\Hydrator;
|
||||
|
||||
use Mailgun\Exception\HydrationException;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
@ -21,6 +22,8 @@ interface Hydrator
|
||||
* @param string $class
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @throws HydrationException
|
||||
*/
|
||||
public function hydrate(ResponseInterface $response, $class);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Mailgun\Hydrator;
|
||||
|
||||
use Mailgun\Exception\DeserializeException;
|
||||
use Mailgun\Exception\HydrationException;
|
||||
use Mailgun\Model\ApiResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
@ -31,12 +31,12 @@ final class ModelHydrator implements Hydrator
|
||||
$body = $response->getBody()->__toString();
|
||||
$contentType = $response->getHeaderLine('Content-Type');
|
||||
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);
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user