fix: catch RestClientException in getProductByReference for PS false response

Spring 6 RestClient wraps HttpMessageNotReadableException (thrown when
deserializing {"products":false}) into RestClientException with message
"Error while extracting response for type [...]". The previous fix only
caught HttpMessageConversionException directly, missing the wrapper.

PrestashopApiException is not a RestClientException, so 4xx/5xx error
handling is unaffected.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
luklpz 2026-05-17 18:19:31 +02:00
parent ca7948d6e6
commit 776e761a94
1 changed files with 5 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConversionException;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestClientException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
@ -88,9 +89,10 @@ public class PrestashopClient {
// PS may return 404 instead of 200+empty when filter finds no results
if (e.getStatusCode() != null && e.getStatusCode().value() == 404) return Optional.empty();
throw e;
} catch (HttpMessageConversionException e) {
// PS 8.x returns {"products": false} instead of {"products": []} when filter has no results
log.debug("PS returned unparseable body for reference filter={}, treating as not found", reference);
} catch (HttpMessageConversionException | RestClientException e) {
// PS 8.x returns {"products": false} instead of {"products": []} when filter has no results.
// Spring 6 RestClient wraps the JSON parse failure in RestClientException.
log.debug("PS returned unparseable body for reference={}, treating as not found: {}", reference, e.getMessage());
return Optional.empty();
}
}