Improve logging in DistanceApiService and DistanceMatrixRepository: Add fallback to names when external mapping IDs are null, fix inconsistent spacing, and enhance error messages with better node ID resolution.
This commit is contained in:
parent
8ef279e735
commit
23bc00d33c
2 changed files with 10 additions and 7 deletions
|
|
@ -88,7 +88,7 @@ public class DistanceMatrixRepository {
|
|||
toId);
|
||||
|
||||
logger.info("Updated existing distance entry for nodes {} -> {}",
|
||||
distance.getFromNodeId(), distance.getToNodeId());
|
||||
fromId, toId);
|
||||
} else {
|
||||
// Insert new entry
|
||||
String insertQuery = """
|
||||
|
|
@ -111,11 +111,14 @@ public class DistanceMatrixRepository {
|
|||
distance.getUpdatedAt());
|
||||
|
||||
logger.info("Inserted new distance entry for nodes {} -> {}",
|
||||
distance.getFromNodeId(), distance.getToNodeId());
|
||||
fromId, toId);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Integer fromId = distance.getFromUserNodeId() != null ? distance.getFromUserNodeId() : distance.getFromNodeId();
|
||||
Integer toId = distance.getToUserNodeId() != null ? distance.getToUserNodeId() : distance.getToNodeId();
|
||||
|
||||
logger.error("Error saving distance to database for nodes {} -> {}",
|
||||
distance.getFromNodeId(), distance.getToNodeId(), e);
|
||||
fromId, toId, e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class DistanceApiService {
|
|||
distanceMatrixRepository.updateRetries(cachedDistance.get().getId());
|
||||
}
|
||||
|
||||
logger.info("Fetching distance from Azure Maps for nodes {} to {}", from.getExternalMappingId(), to.getExternalMappingId());
|
||||
logger.info("Fetching distance from Azure Maps for nodes {} to {}", from.getExternalMappingId() == null ? from.getName() : from.getExternalMappingId(), to.getExternalMappingId() == null ? to.getName() : to.getExternalMappingId());
|
||||
AzureMapResponse distanceResponse = fetchDistanceFromAzureMaps(from, isUsrFrom, to, isUsrTo, true);
|
||||
|
||||
if (distanceResponse.distance != null) {
|
||||
|
|
@ -97,7 +97,7 @@ public class DistanceApiService {
|
|||
return Optional.of(distanceResponse.distance);
|
||||
}
|
||||
|
||||
if(distanceResponse.errorType != AzureMapsErrorType.NO_ERROR) {
|
||||
if (distanceResponse.errorType != AzureMapsErrorType.NO_ERROR) {
|
||||
distanceMatrixRepository.saveDistance(getErrorDistance(cachedDistance, from, isUsrFrom, to, isUsrTo));
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ public class DistanceApiService {
|
|||
distance.setUpdatedAt(LocalDateTime.now());
|
||||
distance.setRetries(distance.getRetries() == null ? 0 : distance.getRetries() + 1);
|
||||
|
||||
if(cachedDistance.isEmpty()) {
|
||||
if (cachedDistance.isEmpty()) {
|
||||
distance.setFromUserNodeId(isUsrFrom ? from.getId() : null);
|
||||
distance.setFromNodeId(isUsrFrom ? null : from.getId());
|
||||
distance.setToUserNodeId(isUsrTo ? to.getId() : null);
|
||||
|
|
@ -208,7 +208,7 @@ public class DistanceApiService {
|
|||
String errorMessage = errorNode.path("error").path("message").asText();
|
||||
|
||||
logger.warn("Azure Maps API Error for nodes {} ({}) to {} ({}): {} - {}",
|
||||
from.getExternalMappingId(), from.getId(), to.getExternalMappingId(), to.getId(),
|
||||
from.getExternalMappingId() == null ? from.getName() : from.getExternalMappingId(), from.getId(), to.getExternalMappingId() == null ? to.getName() : to.getExternalMappingId(), to.getId(),
|
||||
errorCode, errorMessage);
|
||||
|
||||
if (errorMessage.contains("NO_ROUTE_FOUND"))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue