Skip to content

Commit

Permalink
fix(checkins): read error message from response body
Browse files Browse the repository at this point in the history
  • Loading branch information
subzero10 committed Jan 7, 2025
1 parent 287f6a5 commit b0823ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Exceptions/ServiceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ public static function missingPersonalAuthToken(): self
{
return new static("Missing personal auth token. This token is required to use Honeybadger's Data APIs.");
}

/**
* @param string $message
* @return self
*/
public static function withMessage(string $message): self
{
return new static($message);
}
}
8 changes: 8 additions & 0 deletions src/Exceptions/ServiceExceptionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function make(bool $isFromEventsApi = false): ServiceException

private function exception(bool $isFromEventsApi = false): ServiceException
{
$message = $this->response->getBody()->getContents();
if (!empty($message)) {
$data = json_decode($message, true);
if (isset($data['errors'])) {
return ServiceException::withMessage($data['errors']);
}
}

if ($this->response->getStatusCode() === Response::HTTP_FORBIDDEN) {
return ServiceException::invalidApiKey();
}
Expand Down

0 comments on commit b0823ec

Please sign in to comment.