Expose response code from HttpClientException (#371)

This commit is contained in:
Sean Johnson 2017-06-24 00:46:48 -05:00 committed by Tobias Nyholm
parent e800038f21
commit 273b48343d
2 changed files with 16 additions and 2 deletions

View File

@ -27,6 +27,11 @@ final class HttpClientException extends \RuntimeException implements Exception
*/
private $responseBody;
/**
* @var int
*/
private $responseCode;
/**
* @param string $message
* @param int $code
@ -38,6 +43,7 @@ final class HttpClientException extends \RuntimeException implements Exception
if ($response) {
$this->response = $response;
$this->responseCode = $response->getStatusCode();
$body = $response->getBody()->__toString();
if (strpos($response->getHeaderLine('Content-Type'), 'application/json') !== 0) {
$this->responseBody['message'] = $body;
@ -82,4 +88,12 @@ final class HttpClientException extends \RuntimeException implements Exception
{
return $this->responseBody;
}
/**
* @return int
*/
public function getResponseCode()
{
return $this->responseCode;
}
}

View File

@ -18,12 +18,12 @@ final class HttpServerException extends \RuntimeException implements Exception
{
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)
{
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)