diff --git a/src/Capabilities/CapabilityClient.php b/src/Capabilities/CapabilityClient.php index 486c9e7..d1de1bc 100644 --- a/src/Capabilities/CapabilityClient.php +++ b/src/Capabilities/CapabilityClient.php @@ -4,6 +4,7 @@ use Closure; use Exception; +use GuzzleHttp\Exception\ClientException; use Outl1ne\NovaOpenAI\OpenAI; use GuzzleHttp\Promise\Promise; use Outl1ne\NovaOpenAI\StreamHandler; @@ -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(); }