Skip to content

Commit

Permalink
feat: add events api exception message
Browse files Browse the repository at this point in the history
Closes #210
  • Loading branch information
subzero10 committed Nov 1, 2024
1 parent 3eb1947 commit cfb674e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ public static function rateLimit(): self
return new static('You have hit your exception rate limit.');
}

/**
* @return ServiceException
*/
public static function eventsRateLimit(): self
{
return new static('You have hit your events rate limit.');
}

/**
* @return ServiceException
*/
Expand Down
10 changes: 6 additions & 4 deletions src/Exceptions/ServiceExceptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public function __construct(ResponseInterface $response)
$this->response = $response;
}

public function make(): ServiceException
public function make(bool $isFromEventsApi = false): ServiceException
{
return $this->exception();
return $this->exception($isFromEventsApi);
}

private function exception(): ServiceException
private function exception(bool $isFromEventsApi = false): ServiceException
{
if ($this->response->getStatusCode() === Response::HTTP_FORBIDDEN) {
return ServiceException::invalidApiKey();
Expand All @@ -36,7 +36,9 @@ private function exception(): ServiceException
}

if ($this->response->getStatusCode() === Response::HTTP_TOO_MANY_REQUESTS) {
return ServiceException::rateLimit();
return $isFromEventsApi
? ServiceException::eventsRateLimit()
: ServiceException::rateLimit();
}

if ($this->response->getStatusCode() === Response::HTTP_INTERNAL_SERVER_ERROR) {
Expand Down
2 changes: 1 addition & 1 deletion src/HoneybadgerClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function events(array $events): void
}

if ($response->getStatusCode() !== Response::HTTP_CREATED) {
$this->handleEventsException((new ServiceExceptionFactory($response))->make());
$this->handleEventsException((new ServiceExceptionFactory($response))->make(true));
}
}

Expand Down

0 comments on commit cfb674e

Please sign in to comment.