mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-26 06:46:08 +03:00
Avoid fatal error when deserializing unauthorized requests (#282)
This commit is contained in:
parent
2d83ab3bf8
commit
e67ef95d5b
@ -12,6 +12,7 @@ namespace Mailgun\Api;
|
|||||||
use Http\Client\Exception as HttplugException;
|
use Http\Client\Exception as HttplugException;
|
||||||
use Http\Client\HttpClient;
|
use Http\Client\HttpClient;
|
||||||
use Mailgun\Deserializer\ResponseDeserializer;
|
use Mailgun\Deserializer\ResponseDeserializer;
|
||||||
|
use Mailgun\Exception\HttpClientException;
|
||||||
use Mailgun\Exception\HttpServerException;
|
use Mailgun\Exception\HttpServerException;
|
||||||
use Mailgun\RequestBuilder;
|
use Mailgun\RequestBuilder;
|
||||||
use Mailgun\Resource\Api\ErrorResponse;
|
use Mailgun\Resource\Api\ErrorResponse;
|
||||||
@ -59,14 +60,18 @@ abstract class HttpApi
|
|||||||
* @param ResponseInterface $response
|
* @param ResponseInterface $response
|
||||||
* @param string $className
|
* @param string $className
|
||||||
*
|
*
|
||||||
|
* @throws HttpClientException
|
||||||
|
*
|
||||||
* @return object $class
|
* @return object $class
|
||||||
*/
|
*/
|
||||||
protected function safeDeserialize(ResponseInterface $response, $className)
|
protected function safeDeserialize(ResponseInterface $response, $className)
|
||||||
{
|
{
|
||||||
if ($response->getStatusCode() !== 200) {
|
if ($response->getStatusCode() === 200) {
|
||||||
return $this->deserializer->deserialize($response, ErrorResponse::class);
|
|
||||||
} else {
|
|
||||||
return $this->deserializer->deserialize($response, $className);
|
return $this->deserializer->deserialize($response, $className);
|
||||||
|
} elseif ($response->getStatusCode() === 401) {
|
||||||
|
throw HttpClientException::unauthorized();
|
||||||
|
} else {
|
||||||
|
return $this->deserializer->deserialize($response, ErrorResponse::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user