summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRichard Leland <rich@richleland.com>2016-05-03 21:12:27 -0400
committerRichard Leland <rich@richleland.com>2016-05-03 21:12:27 -0400
commitd96d825aa138af92628ec7311c05e9659917ba79 (patch)
treec14aab1ebf1d7a50f9b72dce78679e54dd4942e0 /lib
parent48fcc7b0d1eb204a0a49c50f85dde16fbcb5c6b5 (diff)
downloadphp-sparkpost-d96d825aa138af92628ec7311c05e9659917ba79.zip
php-sparkpost-d96d825aa138af92628ec7311c05e9659917ba79.tar.gz
php-sparkpost-d96d825aa138af92628ec7311c05e9659917ba79.tar.bz2
Return extended exception data
* Update examples to show available extra exception methods * Resolves #83 * Update 403s to pass back extended exception data Fixes #83
Diffstat (limited to 'lib')
-rw-r--r--lib/SparkPost/APIResource.php11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/SparkPost/APIResource.php b/lib/SparkPost/APIResource.php
index 10305f2..f593038 100644
--- a/lib/SparkPost/APIResource.php
+++ b/lib/SparkPost/APIResource.php
@@ -131,7 +131,7 @@ class APIResource {
* assembles a URL for a request
* @param string $resourcePath path after the initial endpoint
* @param array $options array with an optional value of query with values to build a querystring from. Any
- * query elements that are themselves arrays will be imploded into a comma separated list.
+ * query elements that are themselves arrays will be imploded into a comma separated list.
* @return string the assembled URL
*/
private function buildUrl($resourcePath, $options) {
@@ -202,7 +202,14 @@ class APIResource {
return json_decode($response->getBody()->getContents(), true);
}
elseif ($statusCode === 403) {
- throw new APIResponseException('Request forbidden. Does this API Key have the correct SparkPost permissions?');
+ $response = json_decode($response->getBody(), true);
+ throw new APIResponseException(
+ 'Request forbidden',
+ $statusCode,
+ isset($response['errors'][0]['message']) ? $response['errors'][0]['message'] : "Request forbidden",
+ isset($response['errors'][0]['code']) ? $response['errors'][0]['code'] : 1100,
+ isset($response['errors'][0]['description']) ? $response['errors'][0]['description'] : "Does this API Key have the correct permissions?"
+ );
}
elseif ($statusCode === 404) {
throw new APIResponseException('The specified resource does not exist', 404);