File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 55
66namespace Codewithkyrian \ChromaDB \Generated ;
77
8+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaConnectionException ;
89use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaException ;
910use Codewithkyrian \ChromaDB \Generated \Models \Collection ;
1011use Codewithkyrian \ChromaDB \Generated \Models \Database ;
2122use Codewithkyrian \ChromaDB \Generated \Responses \GetItemsResponse ;
2223use Codewithkyrian \ChromaDB \Generated \Responses \QueryItemsResponse ;
2324use GuzzleHttp \Client ;
25+ use GuzzleHttp \Exception \ConnectException ;
2426use GuzzleHttp \Exception \RequestException ;
2527use Psr \Http \Client \ClientExceptionInterface ;
2628
@@ -318,6 +320,13 @@ public function reset(): bool
318320
319321 private function handleChromaApiException (\Exception |ClientExceptionInterface $ e ): void
320322 {
323+ if ($ e instanceof ConnectException) {
324+ $ context = $ e ->getHandlerContext ();
325+ $ message = $ context ['error ' ] ?? $ e ->getMessage ();
326+ $ code = $ context ['errno ' ] ?? $ e ->getCode ();
327+ throw new ChromaConnectionException ($ message , $ code );
328+ }
329+
321330 if ($ e instanceof RequestException) {
322331 $ errorString = $ e ->getResponse ()->getBody ()->getContents ();
323332
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Codewithkyrian \ChromaDB \Generated \Exceptions ;
6+
7+
8+ class ChromaConnectionException extends ChromaException
9+ {
10+
11+ }
Original file line number Diff line number Diff line change 55use Codewithkyrian \ChromaDB \Client ;
66use Codewithkyrian \ChromaDB \ChromaDB ;
77use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaAuthorizationException ;
8+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaConnectionException ;
89
910it ('can connect to a normal chroma server ' , function () {
1011 $ client = ChromaDB::client ();
4243 ->withPort (8001 )
4344 ->connect ();
4445})->throws (ChromaAuthorizationException::class);
46+
47+ it ('throws a connection exception when connecting to a non-existent chroma server ' , function () {
48+ ChromaDB::factory ()
49+ ->withHost ('http://localhost ' )
50+ ->withPort (8002 )
51+ ->connect ();
52+ })->throws (ChromaConnectionException::class);
You can’t perform that action at this time.
0 commit comments