Skip to content

Commit

Permalink
Issue #561: fixed enrichment error reporting via Websocket - had to b…
Browse files Browse the repository at this point in the history
…e wrapped in a DittoProtocol message

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch-si.com>
  • Loading branch information
thjaeckle committed Jan 24, 2020
1 parent ef07c6b commit 6f3bcab
Showing 1 changed file with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ private static Function<SessionedJsonifiable, CompletionStage<Collection<String>
matchesFilter(sessionedJsonifiable, extra)
? Collections.singletonList(toJsonStringWithExtra(adaptable, extra))
: Collections.emptyList())
.exceptionally(WebSocketRoute::reportEnrichmentError);
.exceptionally(error -> WebSocketRoute.reportEnrichmentError(error, adapter, adaptable));
};
}

Expand All @@ -664,14 +664,30 @@ private static TopicPath.Channel determineChannel(final SessionedJsonifiable ses
});
}

private static Collection<String> reportEnrichmentError(final Throwable error) {
private static Collection<String> reportEnrichmentError(final Throwable error,
final ProtocolAdapter adapter,
final Adaptable adaptable) {
final DittoRuntimeException errorToReport;
if (error instanceof DittoRuntimeException) {
errorToReport = ((DittoRuntimeException) error);
} else {
errorToReport = SignalEnrichmentFailedException.newBuilder().build();
errorToReport = SignalEnrichmentFailedException.newBuilder()
.dittoHeaders(adaptable.getDittoHeaders())
.cause(error)
.build();
}
return Collections.singletonList(errorToReport.toJsonString());
LOGGER.withCorrelationId(adaptable.getDittoHeaders())
.error("Signal enrichment failed due to: {}", error.getMessage(), errorToReport);

final JsonifiableAdaptable errorAdaptable =
ProtocolFactory.wrapAsJsonifiableAdaptable(adapter.toAdaptable(
ThingErrorResponse.of(
ThingId.of(adaptable.getTopicPath().getNamespace(), adaptable.getTopicPath().getId()),
errorToReport,
adaptable.getDittoHeaders()
)
));
return Collections.singletonList(errorAdaptable.toJsonString());
}

private static String toJsonStringWithExtra(final Adaptable adaptable, final JsonObject extra) {
Expand Down

0 comments on commit 6f3bcab

Please sign in to comment.