Skip to content

Commit

Permalink
fix(exception-handling): [eclipse-tractusx#841] resolve todo
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmf committed Aug 2, 2024
1 parent bbe6fef commit 5715943
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ public ItemContainer process(final ItemContainer.ItemContainerBuilder itemContai
itemContainerBuilder.shell(
jobData.isAuditContractNegotiation() ? shell : shell.withoutContractAgreementId());

} catch (final ShellNotFoundException e) {
log.info("Shell not found for item: {}. Creating Tombstone.", itemId);
createShellNotFoundTombstone(itemContainerBuilder, itemId, e);
} catch (final RegistryServiceException | RuntimeException e) {
// catching generic exception is intended here,
// otherwise Jobs stay in state RUNNING forever
log.info("Shell could not be retrieved for item: {}. Creating Tombstone.", itemId);
createShellEndpointCouldNotBeRetrievedTombstone(itemContainerBuilder, itemId, e);
}

Expand All @@ -97,13 +101,22 @@ public ItemContainer process(final ItemContainer.ItemContainerBuilder itemContai
return itemContainerBuilder.build();
}

private void createShellNotFoundTombstone(final ItemContainer.ItemContainerBuilder itemContainerBuilder,
final PartChainIdentificationKey itemId, final ShellNotFoundException exception) {
final String endpointURL = String.join("; ", exception.getCalledEndpoints());
final Tombstone tombstone = createTombstone(itemId, exception, endpointURL);
itemContainerBuilder.tombstone(tombstone);
}

private void createShellEndpointCouldNotBeRetrievedTombstone(
final ItemContainer.ItemContainerBuilder itemContainerBuilder, final PartChainIdentificationKey itemId,
final Exception exception) {
final Tombstone tombstone = createTombstone(itemId, exception, /* endpoint URL is unknown here */ null);
itemContainerBuilder.tombstone(tombstone);
}

// TODO (mfischer) is this log message and method name correct?
log.info("Shell Endpoint could not be retrieved for Item: {}. Creating Tombstone.", itemId);
log.debug(exception.getMessage(), exception);
private Tombstone createTombstone(final PartChainIdentificationKey itemId, final Exception exception,
final String endpointURL) {

final List<String> rootErrorMessages = Tombstone.getRootErrorMessages(exception.getSuppressed());
final ProcessingError error = ProcessingError.builder()
Expand All @@ -113,18 +126,12 @@ private void createShellEndpointCouldNotBeRetrievedTombstone(
.withRootCauses(rootErrorMessages)
.build();

String endpointURL = null;
if (exception instanceof ShellNotFoundException) {
endpointURL = String.join("; ", ((ShellNotFoundException) exception).getCalledEndpoints());
}

final Tombstone tombstone = Tombstone.builder()
.endpointURL(endpointURL)
.catenaXId(itemId.getGlobalAssetId())
.processingError(error)
.businessPartnerNumber(itemId.getBpn())
.build();
itemContainerBuilder.tombstone(tombstone);
return Tombstone.builder()
.endpointURL(endpointURL)
.catenaXId(itemId.getGlobalAssetId())
.processingError(error)
.businessPartnerNumber(itemId.getBpn())
.build();
}

private Tombstone createNoBpnProvidedTombstone(final JobParameter jobData,
Expand Down

0 comments on commit 5715943

Please sign in to comment.