Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Add Laravel error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
gregpriday committed Mar 16, 2024
1 parent fcc52ea commit 5604e98
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/ClaudeChat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\HandlerStack;
use GuzzleRetry\GuzzleRetryMiddleware;
use Illuminate\Support\Facades\Log;
use stdClass;

class ClaudeChat
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5604e98

Please sign in to comment.