Skip to content

Commit

Permalink
Merge pull request #71 from outl1ne/guzzle-client-exception-logging
Browse files Browse the repository at this point in the history
feat: enhance exception handling in CapabilityClient
  • Loading branch information
allantatter authored Nov 13, 2024
2 parents 2b7f7b3 + daffc14 commit 1e156ac
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Capabilities/CapabilityClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Exception;
use GuzzleHttp\Exception\ClientException;
use Outl1ne\NovaOpenAI\OpenAI;
use GuzzleHttp\Promise\Promise;
use Outl1ne\NovaOpenAI\StreamHandler;
Expand Down Expand Up @@ -128,11 +129,17 @@ protected function handleCachedResponse(CachedResponse $cachedResponse, ?callabl
return $cachedResponse;
}

public function handleException(Exception $e)
public function handleException(ClientException|Exception $e)
{
$this->request->time_sec = $this->measure();
$this->request->status = 'error';
$this->request->error = $e->getMessage();

if ($e instanceof ClientException) {
$this->request->error = $e->getResponse()->getBody()->getContents();
} else {
$this->request->error = $e->getMessage();
}

if (($this->capability->shouldStoreCallback)() && ($this->capability->shouldStoreErrorsCallback)($e)) {
$this->request->save();
}
Expand Down

0 comments on commit 1e156ac

Please sign in to comment.