Skip to content

Commit 34a4ae3

Browse files
j4m3srichleland
authored andcommitted
Improve Exception message on 403 response (#71)
Fixes #70.
1 parent acb590e commit 34a4ae3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/SparkPost/APIResource.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ private function callResource( $action, $resourcePath=null, $options=[] ) {
193193
if ($statusCode < 400) {
194194
return json_decode($response->getBody()->getContents(), true);
195195
}
196+
elseif ($statusCode === 403) {
197+
throw new APIResponseException('Request forbidden. Does this API Key have the correct SparkPost permissions?');
198+
}
196199
elseif ($statusCode === 404) {
197200
throw new APIResponseException('The specified resource does not exist', 404);
198201
}

test/unit/APIResourceTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ public function testAdapter404Exception() {
111111
}
112112
}
113113

114+
public function testAdapter403Exception() {
115+
try {
116+
$responseMock = Mockery::mock();
117+
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
118+
once()->
119+
andReturn($responseMock);
120+
$responseMock->shouldReceive('getStatusCode')->andReturn(403);
121+
122+
$this->resource->get('test');
123+
}
124+
catch(\Exception $e) {
125+
$this->assertRegExp('/Request forbidden/', $e->getMessage());
126+
}
127+
}
128+
114129
public function testAdapter4XXException() {
115130
try {
116131
$testBody = ['errors'=>['my'=>'test']];

0 commit comments

Comments
 (0)