@@ -266,26 +266,40 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
266
266
->getContents (), true , 512 , JSON_THROW_ON_ERROR ) : $ response ->getBody ()
267
267
->getContents ();
268
268
} catch (HttpException $ exception ) {
269
- if (
270
- $ exception -> getResponse ()
271
- -> getStatusCode () === 408
272
- ) {
269
+ $ statusCode = $ exception -> getResponse ()-> getStatusCode ();
270
+
271
+ // Skip 408 timeouts and continue to next iteration
272
+ if ( $ statusCode === 408 ) {
273
273
continue ;
274
274
}
275
+
276
+ // For 4xx errors, don't retry - throw immediately
277
+ if (400 <= $ statusCode && $ statusCode < 500 ) {
278
+ $ this ->setNodeHealthCheck ($ node , false );
279
+ throw $ this ->getException ($ statusCode )
280
+ ->setMessage ($ exception ->getMessage ());
281
+ }
282
+
283
+ // For 5xx errors, set exception and continue to retry logic
275
284
$ this ->setNodeHealthCheck ($ node , false );
276
- throw $ this ->getException ($ exception ->getResponse ()
277
- ->getStatusCode ())
285
+ $ lastException = $ this ->getException ($ statusCode )
278
286
->setMessage ($ exception ->getMessage ());
279
- } catch (TypesenseClientError | HttpClientException $ exception ) {
287
+ } catch (HttpClientException $ exception ) {
288
+ // For network errors, set exception and continue to retry logic
280
289
$ this ->setNodeHealthCheck ($ node , false );
281
- throw $ exception ;
290
+ $ lastException = $ exception ;
282
291
} catch (Exception $ exception ) {
292
+ if ($ exception instanceof TypesenseClientError) {
293
+ throw $ exception ;
294
+ }
295
+
283
296
$ this ->setNodeHealthCheck ($ node , false );
284
297
$ lastException = $ exception ;
285
- if ($ numRetries < $ this ->config ->getNumRetries () + 1 ) {
286
- sleep ($ this ->config ->getRetryIntervalSeconds ());
287
- }
288
298
}
299
+
300
+ if ($ numRetries < $ this ->config ->getNumRetries () + 1 ) {
301
+ usleep ((int ) ($ this ->config ->getRetryIntervalSeconds () * 10 **6 ));
302
+ }
289
303
}
290
304
291
305
if ($ lastException ) {
0 commit comments