diff options
author | matt <matt@twilio.com> | 2016-09-14 10:25:15 -0700 |
---|---|---|
committer | matt <matt@twilio.com> | 2016-09-14 10:25:15 -0700 |
commit | 8be2852c5496e5e9758180a661e97c6617baac77 (patch) | |
tree | ee7061c176adc368478c7ab21fda74905ebb31ab | |
parent | edfc324e42a82294f5c3dbd38f838c0df57f165f (diff) | |
download | twilio-php-8be2852c5496e5e9758180a661e97c6617baac77.zip twilio-php-8be2852c5496e5e9758180a661e97c6617baac77.tar.gz twilio-php-8be2852c5496e5e9758180a661e97c6617baac77.tar.bz2 |
Update Page::processResponse() with better exceptions
-rw-r--r-- | Twilio/Page.php | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Twilio/Page.php b/Twilio/Page.php index 67e89e2..5e34154 100644 --- a/Twilio/Page.php +++ b/Twilio/Page.php @@ -40,7 +40,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 DeserializeException($message, $code); } return $response->getContent(); } |