Skip to content

Commit

Permalink
#24 Throw exception when api key is not correctly set
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeZ99 committed Feb 1, 2018
1 parent 8445133 commit e1eb4b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Management/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Doofinder\Api\Management\SearchEngine;
use Doofinder\Api\Management\Errors\Utils;
use Doofinder\Api\Management\Errors\InvalidApiKey;

/**
* Class to manage the connection with the API servers.
Expand All @@ -41,6 +42,9 @@ class Client
public function __construct($apiKey, $local = false) {
$this->apiKey = $apiKey;
$clusterToken = explode('-', $apiKey);
if(count($clusterToken) != 2){
throw new InvalidApiKey("Invalid API Key provided");
}
$this->clusterRegion = $clusterToken[0];
$this->token = $clusterToken[1];

Expand Down
5 changes: 5 additions & 0 deletions src/Management/Errors/InvalidApiKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

namespace Doofinder\Api\Management\Errors;

class InvalidApiKey extends \Exception {}

0 comments on commit e1eb4b4

Please sign in to comment.