From 22c92a1ee26595b24288dcb0a046a217ce071dd4 Mon Sep 17 00:00:00 2001 From: luklpz Date: Thu, 14 May 2026 23:51:36 +0200 Subject: [PATCH] fix: throw PrestashopApiException instead of NPE when createProduct returns null If PS accepts the POST but the subsequent GET by reference finds nothing, the null return from createProduct now throws PrestashopApiException, which is caught by the per-item handler and recorded in SyncLog without aborting the rest of the sync loop. Co-Authored-By: Claude Sonnet 4.6 --- .../prestashop/exception/PrestashopApiException.java | 7 +++++++ .../tfg/sync_service/sync/ProductSyncService.java | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/exception/PrestashopApiException.java b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/exception/PrestashopApiException.java index bd62be5..c600601 100644 --- a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/exception/PrestashopApiException.java +++ b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/integration/prestashop/exception/PrestashopApiException.java @@ -17,6 +17,13 @@ public class PrestashopApiException extends RuntimeException { this.body = body; } + /** Use when there is no HTTP status code (e.g. inconsistent API state). */ + public PrestashopApiException(String message) { + super(message); + this.statusCode = null; + this.body = null; + } + public HttpStatusCode getStatusCode() { return statusCode; } public String getBody() { return body; } } diff --git a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/sync/ProductSyncService.java b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/sync/ProductSyncService.java index 061c4e6..33deaae 100644 --- a/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/sync/ProductSyncService.java +++ b/sync-service/src/main/java/com/teterialosjuanjos/tfg/sync_service/sync/ProductSyncService.java @@ -98,6 +98,10 @@ public class ProductSyncService { if (existing.isEmpty()) { PrestashopProductDto created = prestashopClient.createProduct(toPrestashopDto(dolProduct, null)); + if (created == null) { + throw new PrestashopApiException( + "Product created in PS but not found via GET (reference=" + sku + ")"); + } productMappingRepository.save(ProductMapping.builder() .sku(sku) .dolibarrId(dolProduct.id())