Skip to content

Commit 79578ef

Browse files
committed
reduce nesting in telemetry middlewares
1 parent ac58dc4 commit 79578ef

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

commercetools/commercetools-monitoring-datadog/src/main/java/com/commercetools/monitoring/datadog/DatadogMiddleware.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ public CompletableFuture<ApiHttpResponse<byte[]>> invoke(ApiHttpRequest request,
5757
if (response != null) {
5858
statusCode = response.getStatusCode();
5959
}
60+
else if (throwable instanceof ApiHttpException && ((ApiHttpException) throwable).getResponse() != null) {
61+
statusCode = ((ApiHttpException) throwable).getResponse().getStatusCode();
62+
}
6063
else {
61-
if (throwable instanceof ApiHttpException && ((ApiHttpException) throwable).getResponse() != null) {
62-
statusCode = ((ApiHttpException) throwable).getResponse().getStatusCode();
63-
}
64-
else {
65-
statusCode = 0;
66-
}
64+
statusCode = 0;
6765
}
6866
try {
6967
submitClientDurationMetric(request, apiInstance, Duration.between(start, Instant.now()).toMillis(),

commercetools/commercetools-monitoring-newrelic/src/main/java/com/commercetools/monitoring/newrelic/NewRelicTelemetryMiddleware.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,16 @@ public CompletableFuture<ApiHttpResponse<byte[]>> invoke(ApiHttpRequest request,
7171
statusCode = response.getStatusCode();
7272
message = response.getMessage();
7373
}
74+
else if (throwable instanceof ApiHttpException && ((ApiHttpException) throwable).getResponse() != null) {
75+
ApiHttpResponse<byte[]> errorResponse = ((ApiHttpException) throwable).getResponse();
76+
statusCode = errorResponse.getStatusCode();
77+
message = errorResponse.getMessage();
78+
}
7479
else {
75-
if (throwable instanceof ApiHttpException && ((ApiHttpException) throwable).getResponse() != null) {
76-
ApiHttpResponse<byte[]> errorResponse = ((ApiHttpException) throwable).getResponse();
77-
statusCode = errorResponse.getStatusCode();
78-
message = errorResponse.getMessage();
79-
}
80-
else {
81-
statusCode = 0;
82-
message = throwable.getMessage();
83-
}
80+
statusCode = 0;
81+
message = throwable.getMessage();
8482
}
83+
8584
segment.ifPresent(s -> s.reportAsExternal(HttpParameters.library("commercetools-sdk-java-v2")
8685
.uri(request.getUri())
8786
.procedure(request.getMethod().name())

0 commit comments

Comments
 (0)