Skip to content

Commit

Permalink
Throws an exception when no company is found.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdnbrk committed Feb 8, 2019
1 parent c0ad8da commit 6176320
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function parseResponse($response)
throw new KiyohException("Unable to decode response: '{$body}'.");
}

if (isset($object['error'])) {
throw new KiyohException($object['error']);
}

return $object;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,16 @@ public function performing_an_http_call_without_setting_an_company_id_throws_an_

$this->client->performHttpCall();
}

/** @test */
public function performing_an_http_call_with_invalid_credentials_throws_an_error()
{
$this->expectException(KiyohException::class);
$this->expectExceptionMessage('No company found.');

$this->client->setApiKey('invalid-api-key');
$this->client->setCompanyId('99999');

$this->client->performHttpCall();
}
}

0 comments on commit 6176320

Please sign in to comment.