@@ -569,4 +569,67 @@ public function testDrainedResponseBodyStillDecodesWithoutRetrying(): void
569569 $ this ->assertSame (['ok ' => true ], $ result );
570570 $ this ->assertSame (1 , $ callCount );
571571 }
572+
573+ public function testEvery408AttemptStillThrowsInsteadOfReturningNothing (): void
574+ {
575+ $ callCount = 0 ;
576+
577+ $ httpClient = $ this ->createMock (ClientInterface::class);
578+ $ httpClient ->method ('sendRequest ' )
579+ ->willReturnCallback (function () use (&$ callCount ) {
580+ $ callCount ++;
581+
582+ $ response = $ this ->createMock (ResponseInterface::class);
583+ $ response ->method ('getStatusCode ' )->willReturn (408 );
584+ throw new HttpException ('Request timeout ' , $ this ->createMock (RequestInterface::class), $ response );
585+ });
586+
587+ $ config = new Configuration ([
588+ 'api_key ' => 'test-key ' ,
589+ 'nodes ' => [
590+ ['host ' => 'node1 ' , 'port ' => 8108 , 'protocol ' => 'http ' ],
591+ ['host ' => 'node2 ' , 'port ' => 8108 , 'protocol ' => 'http ' ]
592+ ],
593+ 'num_retries ' => 2 ,
594+ 'retry_interval_seconds ' => 0 ,
595+ 'client ' => $ httpClient
596+ ]);
597+
598+ $ apiCall = new ApiCall ($ config );
599+
600+ try {
601+ $ result = $ apiCall ->get ('/test ' , []);
602+ $ this ->fail ('Expected a TypesenseClientError, got ' . var_export ($ result , true ));
603+ } catch (TypesenseClientError $ exception ) {
604+ $ this ->assertSame (408 , $ exception ->getCode ());
605+ $ this ->assertSame ('Request timeout ' , $ exception ->getMessage ());
606+ }
607+
608+ $ this ->assertSame (3 , $ callCount );
609+ }
610+
611+ public function testSearchSurfacesATimeoutWhenEveryAttemptReturns408 (): void
612+ {
613+ $ httpClient = $ this ->createMock (ClientInterface::class);
614+ $ httpClient ->method ('sendRequest ' )
615+ ->willReturnCallback (function () {
616+ $ response = $ this ->createMock (ResponseInterface::class);
617+ $ response ->method ('getStatusCode ' )->willReturn (408 );
618+ throw new HttpException ('Request timeout ' , $ this ->createMock (RequestInterface::class), $ response );
619+ });
620+
621+ $ client = new \Typesense \Client ([
622+ 'api_key ' => 'test-key ' ,
623+ 'nodes ' => [
624+ ['host ' => 'node1 ' , 'port ' => 8108 , 'protocol ' => 'http ' ]
625+ ],
626+ 'num_retries ' => 1 ,
627+ 'retry_interval_seconds ' => 0 ,
628+ 'client ' => $ httpClient
629+ ]);
630+
631+ $ this ->expectException (TypesenseClientError::class);
632+
633+ $ client ->collections ['books ' ]->documents ->search (['q ' => '* ' , 'query_by ' => 'title ' ]);
634+ }
572635}
0 commit comments