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:
parent
ca7948d6e6
commit
776e761a94
|
|
@ -9,6 +9,7 @@ import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.converter.HttpMessageConversionException;
|
import org.springframework.http.converter.HttpMessageConversionException;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -88,9 +89,10 @@ public class PrestashopClient {
|
||||||
// PS may return 404 instead of 200+empty when filter finds no results
|
// PS may return 404 instead of 200+empty when filter finds no results
|
||||||
if (e.getStatusCode() != null && e.getStatusCode().value() == 404) return Optional.empty();
|
if (e.getStatusCode() != null && e.getStatusCode().value() == 404) return Optional.empty();
|
||||||
throw e;
|
throw e;
|
||||||
} catch (HttpMessageConversionException e) {
|
} catch (HttpMessageConversionException | RestClientException e) {
|
||||||
// PS 8.x returns {"products": false} instead of {"products": []} when filter has no results
|
// 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);
|
// 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();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue