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 <noreply@anthropic.com>
This commit is contained in:
parent
4ae72e3e05
commit
22c92a1ee2
|
|
@ -17,6 +17,13 @@ public class PrestashopApiException extends RuntimeException {
|
||||||
this.body = body;
|
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 HttpStatusCode getStatusCode() { return statusCode; }
|
||||||
public String getBody() { return body; }
|
public String getBody() { return body; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,10 @@ public class ProductSyncService {
|
||||||
|
|
||||||
if (existing.isEmpty()) {
|
if (existing.isEmpty()) {
|
||||||
PrestashopProductDto created = prestashopClient.createProduct(toPrestashopDto(dolProduct, null));
|
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()
|
productMappingRepository.save(ProductMapping.builder()
|
||||||
.sku(sku)
|
.sku(sku)
|
||||||
.dolibarrId(dolProduct.id())
|
.dolibarrId(dolProduct.id())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue