fix: catch RestClientException in all sync services
Per-item catch blocks only handled DolibarrApiException|PrestashopApiException, letting network-level errors (RestClientException wrapping SSL, timeout, etc.) propagate uncaught → HTTP 500. Also add outer catch for infrastructure failures (e.g. getProducts() itself failing) so SyncLog always records the error in errorDetails and the service returns a valid SyncResult instead of throwing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
cfce84eb4d
commit
121dc329f8
|
|
@ -14,6 +14,7 @@ import com.teterialosjuanjos.tfg.sync_service.mapping.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
@ -83,13 +84,18 @@ public class OrderSyncService {
|
||||||
try {
|
try {
|
||||||
importOrder(psOrder);
|
importOrder(psOrder);
|
||||||
processed++;
|
processed++;
|
||||||
} catch (DolibarrApiException | PrestashopApiException e) {
|
} catch (DolibarrApiException | PrestashopApiException | RestClientException e) {
|
||||||
failed++;
|
failed++;
|
||||||
String msg = "PS order %d: %s".formatted(psOrder.id(), e.getMessage());
|
String msg = "PS order %d: %s".formatted(psOrder.id(), e.getMessage());
|
||||||
errors.add(msg);
|
errors.add(msg);
|
||||||
log.warn("OrderSync item failed: {}", msg);
|
log.warn("OrderSync item failed: {}", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
failed++;
|
||||||
|
String msg = "Failed to fetch orders from PrestaShop: " + e.getMessage();
|
||||||
|
errors.add(msg);
|
||||||
|
log.error("OrderSync infrastructure error: {}", msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
syncLog.setFinishedAt(Instant.now());
|
syncLog.setFinishedAt(Instant.now());
|
||||||
syncLog.setItemsProcessed(processed);
|
syncLog.setItemsProcessed(processed);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import com.teterialosjuanjos.tfg.sync_service.mapping.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -68,7 +69,7 @@ public class ProductSyncService {
|
||||||
try {
|
try {
|
||||||
pushProduct(product);
|
pushProduct(product);
|
||||||
processed++;
|
processed++;
|
||||||
} catch (DolibarrApiException | PrestashopApiException e) {
|
} catch (DolibarrApiException | PrestashopApiException | RestClientException e) {
|
||||||
failed++;
|
failed++;
|
||||||
String msg = "SKU %s: %s".formatted(product.ref(), e.getMessage());
|
String msg = "SKU %s: %s".formatted(product.ref(), e.getMessage());
|
||||||
errors.add(msg);
|
errors.add(msg);
|
||||||
|
|
@ -76,6 +77,11 @@ public class ProductSyncService {
|
||||||
markError(product.ref(), e.getMessage());
|
markError(product.ref(), e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
failed++;
|
||||||
|
String msg = "Failed to fetch products from Dolibarr: " + e.getMessage();
|
||||||
|
errors.add(msg);
|
||||||
|
log.error("ProductSync infrastructure error: {}", msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
syncLog.setFinishedAt(Instant.now());
|
syncLog.setFinishedAt(Instant.now());
|
||||||
syncLog.setItemsProcessed(processed);
|
syncLog.setItemsProcessed(processed);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import com.teterialosjuanjos.tfg.sync_service.mapping.*;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -55,13 +56,18 @@ public class StockSyncService {
|
||||||
if (pushStock(mapping)) {
|
if (pushStock(mapping)) {
|
||||||
processed++;
|
processed++;
|
||||||
}
|
}
|
||||||
} catch (DolibarrApiException | PrestashopApiException e) {
|
} catch (DolibarrApiException | PrestashopApiException | RestClientException e) {
|
||||||
failed++;
|
failed++;
|
||||||
String msg = "SKU %s: %s".formatted(mapping.getSku(), e.getMessage());
|
String msg = "SKU %s: %s".formatted(mapping.getSku(), e.getMessage());
|
||||||
errors.add(msg);
|
errors.add(msg);
|
||||||
log.warn("StockSync item failed: {}", msg);
|
log.warn("StockSync item failed: {}", msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (RestClientException e) {
|
||||||
|
failed++;
|
||||||
|
String msg = "Infrastructure error: " + e.getMessage();
|
||||||
|
errors.add(msg);
|
||||||
|
log.error("StockSync infrastructure error: {}", msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
syncLog.setFinishedAt(Instant.now());
|
syncLog.setFinishedAt(Instant.now());
|
||||||
syncLog.setItemsProcessed(processed);
|
syncLog.setItemsProcessed(processed);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue