diff options
author | Matt Nowack <mdnowack@gmail.com> | 2016-09-15 13:28:19 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-15 13:28:19 -0700 |
commit | f2a0741c2ee39aed94825ce022aa9c67f2a5c1ae (patch) | |
tree | 89dd6acabf08bd735881644147b81108b9ad1cb7 | |
parent | bd0ce5e1d81d0b872a39e96d637b9ed4c63e36e5 (diff) | |
parent | d2604e72f162ab3ae0b88467926b8a6e59022f11 (diff) | |
download | twilio-php-f2a0741c2ee39aed94825ce022aa9c67f2a5c1ae.zip twilio-php-f2a0741c2ee39aed94825ce022aa9c67f2a5c1ae.tar.gz twilio-php-f2a0741c2ee39aed94825ce022aa9c67f2a5c1ae.tar.bz2 |
Merge pull request #376 from twilio/better-page-processing
Update Page::processResponse() with better exceptions
-rw-r--r-- | Twilio/Page.php | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Twilio/Page.php b/Twilio/Page.php index 67e89e2..fdbab4a 100644 --- a/Twilio/Page.php +++ b/Twilio/Page.php @@ -5,6 +5,7 @@ namespace Twilio; use Twilio\Exceptions\DeserializeException; +use Twilio\Exceptions\RestException; use Twilio\Http\Response; abstract class Page implements \Iterator { @@ -40,7 +41,17 @@ abstract class Page implements \Iterator { protected function processResponse(Response $response) { if ($response->getStatusCode() != 200 && !$this->isPagingEol($response->getContent())) { - throw new DeserializeException('Unable to fetch page', $response->getStatusCode()); + $message = '[HTTP ' . $response->getStatusCode() . '] Unable to fetch page'; + $code = $response->getStatusCode(); + + $content = $response->getContent(); + + if (is_array($content)) { + $message .= isset($content['message']) ? ': ' . $content['message'] : ''; + $code = isset($content['code']) ? $content['code'] : $code; + } + + throw new RestException($message, $code, $response->getStatusCode()); } return $response->getContent(); } |