From e4b7134a6ec86fa7d98c2e872dbe57488d902c60 Mon Sep 17 00:00:00 2001 From: RayDNoper Date: Mon, 22 Jan 2024 10:05:30 +0200 Subject: [PATCH] #250 REHA: also log when DSL returns non-OK --- src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java | 3 +++ .../java/ee/buerokratt/ruuter/domain/steps/DslStep.java | 1 + .../java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java b/src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java index c1cea5eb..74ba3e1f 100644 --- a/src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java +++ b/src/main/java/ee/buerokratt/ruuter/domain/DslInstance.java @@ -87,6 +87,9 @@ private void executeStep(String stepName, List stepNames) { if (!Objects.equals(recursions.get(stepName), getStepMaxRecursions(stepToExecute))) { try { stepToExecute.execute(this); + if (getErrorStatus() != null && !getErrorStatus().equals(HttpStatus.OK)) { + logEvent(stepToExecute, "RUNTIME", Thread.currentThread().getStackTrace()); + } } catch (StepExecutionException e) { logEvent(stepToExecute, "RUNTIME", e.getStackTrace()); diff --git a/src/main/java/ee/buerokratt/ruuter/domain/steps/DslStep.java b/src/main/java/ee/buerokratt/ruuter/domain/steps/DslStep.java index a5d40ca8..0e668e13 100644 --- a/src/main/java/ee/buerokratt/ruuter/domain/steps/DslStep.java +++ b/src/main/java/ee/buerokratt/ruuter/domain/steps/DslStep.java @@ -12,6 +12,7 @@ import org.springframework.cloud.sleuth.Span; import org.springframework.cloud.sleuth.Tracer; import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpClientErrorException; @Slf4j @Data diff --git a/src/main/java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java b/src/main/java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java index f2824187..45727a57 100644 --- a/src/main/java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java +++ b/src/main/java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java @@ -6,6 +6,8 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.ToString; +import org.springframework.http.HttpStatus; +import org.springframework.web.client.HttpClientErrorException; import java.util.LinkedHashMap; import java.util.Map; @@ -32,6 +34,10 @@ protected void executeStepAction(DslInstance di) { di.setReturnStatus(status); di.setReturnWithWrapper(withWrapper); di.setReturnValue(di.getScriptingHelper().evaluateScripts(returnValue, di.getContext(), di.getRequestBody(), di.getRequestQuery(), di.getRequestHeaders())); + if (status != 200) { + di.setErrorStatus(HttpStatus.valueOf(status)); + di.setErrorMessage(returnValue); + } } @Override