diff --git a/src/ClaudeChat.php b/src/ClaudeChat.php index 3df2387..9662f58 100755 --- a/src/ClaudeChat.php +++ b/src/ClaudeChat.php @@ -6,6 +6,7 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\HandlerStack; use GuzzleRetry\GuzzleRetryMiddleware; +use Illuminate\Support\Facades\Log; use stdClass; class ClaudeChat @@ -57,13 +58,22 @@ public function create(array $arguments): stdClass 'max_tokens' => 4096, ], $arguments); - $response = $this->client->post('', [ - 'json' => $arguments, - ]); - - $responseData = json_decode($response->getBody()->getContents()); - - return $responseData; + try { + $response = $this->client->post('', [ + 'json' => $arguments, + ]); + + return json_decode($response->getBody()->getContents()); + } catch (GuzzleException $e) { + // Log the error with Laravel's logging system + Log::error('Error sending request to the Claude API: ' . $e->getMessage(), [ + 'exception' => $e, + 'arguments' => $arguments, + ]); + + // Optionally, rethrow the exception if you want the caller to handle it + throw $e; + } } public function createJson(array $arguments): stdClass