Skip to content

Commit

Permalink
Add support for disabled api key
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuDeBuck committed Jun 20, 2021
1 parent eacd605 commit a7d3448
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ private function check(ResponseInterface $response)
false,
$this->getRemainingRequests($response),
$this->getMaxRequests($response),
[$json["message"]],
null
[$json["message"]]
);
}

if ($response->getStatusCode() === 403) {
return new CallResult(
false,
false,
$this->getRemainingRequests($response),
$this->getMaxRequests($response),
["the api key is disabled"]
);
}

Expand All @@ -107,8 +116,7 @@ private function check(ResponseInterface $response)
true,
$this->getRemainingRequests($response),
$this->getMaxRequests($response),
["rate limited"],
null
["rate limited"]
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,18 @@ public function test_it_deals_with_unexpected_error()
);
}

public function test_it_deals_with_forbidden_error()
{
$factory = new Psr17Factory();
$http = new HttpClientFixed(new Response(403, [], null));
$client = new Client($http, $factory, $factory, ["apiKey" => "key"]);

$this->assertEquals(
new CallResult(false, false, 0, 0, ["the api key is disabled"], null),
$client->addEvent(Event::forUser("login", UserIdentified::byUserId("1")))
);
}

public function test_it_deals_with_unauthorized_error()
{
$factory = new Psr17Factory();
Expand Down

0 comments on commit a7d3448

Please sign in to comment.