From 776e761a94e92e1eb78f8e5201bf3b9f08c26b41 Mon Sep 17 00:00:00 2001 From: luklpz Date: Sun, 17 May 2026 18:19:31 +0200 Subject: [PATCH] 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 --- .../integration/prestashop/PrestashopClient.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/PrestashopClient.java b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/PrestashopClient.java index 52d72cd..e42ad17 100644 --- a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/PrestashopClient.java +++ b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/PrestashopClient.java @@ -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(); } }