@@ -131,7 +131,7 @@ public function delete( $resourcePath=null, Array $query=[] ) {
131131 * assembles a URL for a request
132132 * @param string $resourcePath path after the initial endpoint
133133 * @param array $options array with an optional value of query with values to build a querystring from. Any
134- * query elements that are themselves arrays will be imploded into a comma separated list.
134+ * query elements that are themselves arrays will be imploded into a comma separated list.
135135 * @return string the assembled URL
136136 */
137137 private function buildUrl ($ resourcePath , $ options ) {
@@ -202,7 +202,14 @@ private function callResource( $action, $resourcePath=null, $options=[] ) {
202202 return json_decode ($ response ->getBody ()->getContents (), true );
203203 }
204204 elseif ($ statusCode === 403 ) {
205- throw new APIResponseException ('Request forbidden. Does this API Key have the correct SparkPost permissions? ' );
205+ $ response = json_decode ($ response ->getBody (), true );
206+ throw new APIResponseException (
207+ 'Request forbidden ' ,
208+ $ statusCode ,
209+ isset ($ response ['errors ' ][0 ]['message ' ]) ? $ response ['errors ' ][0 ]['message ' ] : "Request forbidden " ,
210+ isset ($ response ['errors ' ][0 ]['code ' ]) ? $ response ['errors ' ][0 ]['code ' ] : 1100 ,
211+ isset ($ response ['errors ' ][0 ]['description ' ]) ? $ response ['errors ' ][0 ]['description ' ] : "Does this API Key have the correct permissions? "
212+ );
206213 }
207214 elseif ($ statusCode === 404 ) {
208215 throw new APIResponseException ('The specified resource does not exist ' , 404 );
0 commit comments