mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 12:36:02 +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\HttpClient;
|
||||
use Mailgun\Deserializer\ResponseDeserializer;
|
||||
use Mailgun\Exception\HttpClientException;
|
||||
use Mailgun\Exception\HttpServerException;
|
||||
use Mailgun\RequestBuilder;
|
||||
use Mailgun\Resource\Api\ErrorResponse;
|
||||
@ -59,14 +60,18 @@ abstract class HttpApi
|
||||
* @param ResponseInterface $response
|
||||
* @param string $className
|
||||
*
|
||||
* @throws HttpClientException
|
||||
*
|
||||
* @return object $class
|
||||
*/
|
||||
protected function safeDeserialize(ResponseInterface $response, $className)
|
||||
{
|
||||
if ($response->getStatusCode() !== 200) {
|
||||
return $this->deserializer->deserialize($response, ErrorResponse::class);
|
||||
} else {
|
||||
if ($response->getStatusCode() === 200) {
|
||||
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