File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99namespace Qdrant \Exception ;
1010
1111use Qdrant \Response ;
12+ use RuntimeException ;
1213
13- class ServerException extends \ RuntimeException
14+ class ServerException extends RuntimeException
1415{
1516 protected Response $ response ;
1617
Original file line number Diff line number Diff line change 66namespace Qdrant \Http ;
77
88use GuzzleHttp \Client ;
9- use GuzzleHttp \Exception \ClientException ;
9+ use GuzzleHttp \Exception \RequestException ;
1010use JsonException ;
1111use Psr \Http \Client \ClientExceptionInterface ;
1212use Psr \Http \Message \RequestInterface ;
@@ -51,15 +51,19 @@ public function execute(RequestInterface $request): Response
5151 {
5252 $ request = $ this ->prepareHeaders ($ request );
5353 try {
54- $ res = $ this ->client ->sendRequest ($ request );
54+ $ res = $ this ->client ->send ($ request );
5555
5656 return new Response ($ res );
57- } catch (ClientException $ e ) {
57+ } catch (RequestException $ e ) {
5858 $ statusCode = $ e ->getResponse ()->getStatusCode ();
5959 if ($ statusCode >= 400 && $ statusCode < 500 ) {
60- throw new InvalidArgumentException ($ e ->getMessage ());
60+ $ errorResponse = new Response ($ e ->getResponse ());
61+ throw (new InvalidArgumentException ($ e ->getMessage (), $ statusCode ))
62+ ->setResponse ($ errorResponse );
6163 } elseif ($ statusCode >= 500 ) {
62- throw new ServerException ($ e ->getMessage ());
64+ $ errorResponse = new Response ($ e ->getResponse ());
65+ throw (new ServerException ($ e ->getMessage (), $ statusCode ))
66+ ->setResponse ($ errorResponse );
6367 }
6468 }
6569 }
Original file line number Diff line number Diff line change @@ -31,16 +31,6 @@ public function __construct(protected ResponseInterface $response)
3131 'content ' => $ response ->getBody ()->getContents ()
3232 ];
3333 }
34-
35- if ($ this ->response ->getStatusCode () >= 400 && $ this ->response ->getStatusCode () < 500 ) {
36- throw (new InvalidArgumentException (
37- $ this ->raw ['status ' ]['error ' ] ?? 'Invalid argument exception ' ,
38- $ this ->response ->getStatusCode ()))->setResponse ($ this );
39- }
40-
41- if ($ this ->response ->getStatusCode () >= 500 ) {
42- throw (new ServerException ('Server Exception ' , $ this ->response ->getStatusCode ()))->setResponse ($ this );
43- }
4434 }
4535
4636 public function __toArray (): array
Original file line number Diff line number Diff line change 88
99use Qdrant \Endpoints \Cluster ;
1010use Qdrant \Exception \InvalidArgumentException ;
11+ use Qdrant \Exception \ServerException ;
1112use Qdrant \Tests \Integration \AbstractIntegration ;
1213
1314class ClusterTest extends AbstractIntegration
@@ -29,15 +30,12 @@ public function testClusterInfo(): void
2930 */
3031 public function testClusterRecover (): void
3132 {
33+ $ this ->expectException (ServerException::class);
34+ $ this ->expectExceptionMessage ('500 Internal Server Error ' );
35+ $ this ->expectExceptionCode (500 );
36+
3237 $ cluster = new Cluster ($ this ->client );
3338 $ response = $ cluster ->recover ();
34-
35- $ this ->assertArrayHasKey ('status ' , $ response );
36- $ this ->assertArrayHasKey ('time ' , $ response );
37- $ this ->assertEquals (
38- 'Service internal error: Qdrant is running in standalone mode ' ,
39- $ response ['status ' ]['error ' ]
40- );
4139 }
4240
4341 /**
Original file line number Diff line number Diff line change @@ -48,9 +48,6 @@ public function testConstructResponse2(): void
4848
4949 public function testConstructResponseWith4xxHttpCode (): void
5050 {
51- $ this ->expectException (InvalidArgumentException::class);
52- $ this ->expectExceptionMessage ('Invalid argument exception ' );
53- $ this ->expectExceptionCode (418 );
5451 $ httpResponse = new HttpResponse (
5552 418 ,
5653 [
@@ -59,20 +56,19 @@ public function testConstructResponseWith4xxHttpCode(): void
5956 Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
6057 );
6158
62- new Response ($ httpResponse );
59+ $ response = new Response ($ httpResponse );
60+ $ this ->assertEquals ('bar ' , $ response ['foo ' ]);
6361 }
6462
6563 public function testConstructResponseWith5xxHttpCode (): void
6664 {
67- $ this ->expectException (ServerException::class);
68- $ this ->expectExceptionMessage ('Server Exception ' );
69- $ this ->expectExceptionCode (510 );
7065 $ httpResponse = new HttpResponse (
7166 510 ,
7267 [],
7368 Utils::streamFor (json_encode (['foo ' => 'bar ' ]))
7469 );
7570
76- new Response ($ httpResponse );
71+ $ response = new Response ($ httpResponse );
72+ $ this ->assertEquals ('{"foo":"bar"} ' , $ response ['content ' ]);
7773 }
7874}
You can’t perform that action at this time.
0 commit comments