Skip to content

Commit 2d23ae3

Browse files
author
Nara Kasbergen
committed
fixes #2 - add getStatusText() to ApiException class
1 parent 9986c42 commit 2d23ae3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

docs/NPR-One-Exceptions-ApiException.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ Returns the HTTP status code from the failed API call; should generally always b
5050

5151

5252

53+
### getStatusText
54+
55+
string NPR\One\Exceptions\ApiException::getStatusText()
56+
57+
Returns the HTTP status text (a.k.a. reason phrase) from the failed API call.
58+
59+
60+
61+
* Visibility: **public**
62+
63+
64+
65+
5366
### getBody
5467

5568
\GuzzleHttp\Psr7\Stream NPR\One\Exceptions\ApiException::getBody()

src/One/Exceptions/ApiException.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class ApiException extends \Exception
1919
* @internal
2020
*/
2121
private $statusCode;
22+
/**
23+
* @var string
24+
* @internal
25+
*/
26+
private $statusText;
2227
/**
2328
* @var Stream
2429
* @internal
@@ -37,6 +42,7 @@ public function __construct($message, Response $response)
3742
parent::__construct($message . " - status: {$response->getStatusCode()}, body: {$response->getBody()}");
3843

3944
$this->statusCode = $response->getStatusCode();
45+
$this->statusText = $response->getReasonPhrase();
4046
$this->body = $response->getBody();
4147
}
4248

@@ -50,6 +56,16 @@ public function getStatusCode()
5056
return $this->statusCode;
5157
}
5258

59+
/**
60+
* Returns the HTTP status text (a.k.a. reason phrase) from the failed API call.
61+
*
62+
* @return string
63+
*/
64+
public function getStatusText()
65+
{
66+
return $this->statusText;
67+
}
68+
5369
/**
5470
* Returns the body of the response from the failed API call. May be empty.
5571
*

0 commit comments

Comments
 (0)