Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/SparkPost/APIResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ private function callResource( $action, $resourcePath=null, $options=[] ) {
if ($statusCode < 400) {
return json_decode($response->getBody()->getContents(), true);
}
elseif ($statusCode === 403) {
throw new APIResponseException('Request forbidden. Does this API Key have the correct SparkPost permissions?');
}
elseif ($statusCode === 404) {
throw new APIResponseException('The specified resource does not exist', 404);
}
Expand Down
15 changes: 15 additions & 0 deletions test/unit/APIResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ public function testAdapter404Exception() {
}
}

public function testAdapter403Exception() {
try {
$responseMock = Mockery::mock();
$this->sparkPostMock->httpAdapter->shouldReceive('send')->
once()->
andReturn($responseMock);
$responseMock->shouldReceive('getStatusCode')->andReturn(403);

$this->resource->get('test');
}
catch(\Exception $e) {
$this->assertRegExp('/Request forbidden/', $e->getMessage());
}
}

public function testAdapter4XXException() {
try {
$testBody = ['errors'=>['my'=>'test']];
Expand Down