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 5
5
6
6
namespace Codewithkyrian \ChromaDB \Generated ;
7
7
8
+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaConnectionException ;
8
9
use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaException ;
9
10
use Codewithkyrian \ChromaDB \Generated \Models \Collection ;
10
11
use Codewithkyrian \ChromaDB \Generated \Models \Database ;
21
22
use Codewithkyrian \ChromaDB \Generated \Responses \GetItemsResponse ;
22
23
use Codewithkyrian \ChromaDB \Generated \Responses \QueryItemsResponse ;
23
24
use GuzzleHttp \Client ;
25
+ use GuzzleHttp \Exception \ConnectException ;
24
26
use GuzzleHttp \Exception \RequestException ;
25
27
use Psr \Http \Client \ClientExceptionInterface ;
26
28
@@ -318,6 +320,13 @@ public function reset(): bool
318
320
319
321
private function handleChromaApiException (\Exception |ClientExceptionInterface $ e ): void
320
322
{
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
+
321
330
if ($ e instanceof RequestException) {
322
331
$ errorString = $ e ->getResponse ()->getBody ()->getContents ();
323
332
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 5
5
use Codewithkyrian \ChromaDB \Client ;
6
6
use Codewithkyrian \ChromaDB \ChromaDB ;
7
7
use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaAuthorizationException ;
8
+ use Codewithkyrian \ChromaDB \Generated \Exceptions \ChromaConnectionException ;
8
9
9
10
it ('can connect to a normal chroma server ' , function () {
10
11
$ client = ChromaDB::client ();
42
43
->withPort (8001 )
43
44
->connect ();
44
45
})->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