mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-22 12:36:02 +03:00
Expose response code from HttpClientException (#371)
This commit is contained in:
parent
e800038f21
commit
273b48343d
@ -27,6 +27,11 @@ final class HttpClientException extends \RuntimeException implements Exception
|
|||||||
*/
|
*/
|
||||||
private $responseBody;
|
private $responseBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $responseCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param int $code
|
* @param int $code
|
||||||
@ -38,6 +43,7 @@ final class HttpClientException extends \RuntimeException implements Exception
|
|||||||
|
|
||||||
if ($response) {
|
if ($response) {
|
||||||
$this->response = $response;
|
$this->response = $response;
|
||||||
|
$this->responseCode = $response->getStatusCode();
|
||||||
$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) {
|
||||||
$this->responseBody['message'] = $body;
|
$this->responseBody['message'] = $body;
|
||||||
@ -82,4 +88,12 @@ final class HttpClientException extends \RuntimeException implements Exception
|
|||||||
{
|
{
|
||||||
return $this->responseBody;
|
return $this->responseBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getResponseCode()
|
||||||
|
{
|
||||||
|
return $this->responseCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,12 @@ final class HttpServerException extends \RuntimeException implements Exception
|
|||||||
{
|
{
|
||||||
public static function serverError($httpStatus = 500)
|
public static function serverError($httpStatus = 500)
|
||||||
{
|
{
|
||||||
return new self('An unexpected error occurred at Mailgun\'s servers. Try again later and contact support of the error sill exists.', $httpStatus);
|
return new self('An unexpected error occurred at Mailgun\'s servers. Try again later and contact support if the error sill exists.', $httpStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function networkError(\Exception $previous)
|
public static function networkError(\Exception $previous)
|
||||||
{
|
{
|
||||||
return new self('Mailgun\'s servers was unreachable.', 0, $previous);
|
return new self('Mailgun\'s servers are currently unreachable.', 0, $previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function unknownHttpResponseCode($code)
|
public static function unknownHttpResponseCode($code)
|
||||||
|
Loading…
Reference in New Issue
Block a user