From 3fd055d8954527bc9456e480c3e87e1c1082e72c Mon Sep 17 00:00:00 2001 From: KFilippopolitis Date: Thu, 12 Nov 2026 13:57:18 +0200 Subject: [PATCH] fix(analysis): show the Exaflow message for a 422 response Exaflow now answers 422 when the analysis request body is not JSON or does not match its schema (madgik/exaflow#665). It answered 400 before. 422 was not in the list of Exaflow error statuses, so it was handled as an unexpected status and the user got a 500. It is now passed through with the Exaflow message, like 400. --- src/main/java/hbp/mip/algorithm/AnalysisService.java | 2 +- .../hbp/mip/algorithm/AnalysisServiceRequestIdTest.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/hbp/mip/algorithm/AnalysisService.java b/src/main/java/hbp/mip/algorithm/AnalysisService.java index 020a0fab..530def23 100644 --- a/src/main/java/hbp/mip/algorithm/AnalysisService.java +++ b/src/main/java/hbp/mip/algorithm/AnalysisService.java @@ -67,7 +67,7 @@ public AnalysisResultDTO runAnalysis(UUID requestId, AnalysisRequestDTO analysis static Object convertResponseToAnalysisResult(Logger logger, int code, StringBuilder responseBody) { return switch (code) { case 200 -> new RawJson(responseBody.toString()); - case 400, 413, 460, 461, 462, 512, 513 -> convertExaflowResponseToAnalysisResult(responseBody.toString()); + case 400, 413, 422, 460, 461, 462, 512, 513 -> convertExaflowResponseToAnalysisResult(responseBody.toString()); case 500 -> convertExaflowResponseToAnalysisResult(GENERIC_ERROR_MESSAGE); // Exaflow is at its concurrent-analysis limit; its own message names internal components, // so it goes to the log and the user gets a retry message. diff --git a/src/test/java/hbp/mip/algorithm/AnalysisServiceRequestIdTest.java b/src/test/java/hbp/mip/algorithm/AnalysisServiceRequestIdTest.java index 66dfb419..6d4479b6 100644 --- a/src/test/java/hbp/mip/algorithm/AnalysisServiceRequestIdTest.java +++ b/src/test/java/hbp/mip/algorithm/AnalysisServiceRequestIdTest.java @@ -52,4 +52,12 @@ void convertResponse_passesExaflowMessageTooLargeThrough() { assertThat(AnalysisService.convertResponseToAnalysisResult(new Logger("user", "test"), 413, exaflowBody)) .isEqualTo(Map.of("data", exaflowBody.toString(), "type", "text/plain+error")); } + + @Test + void convertResponse_passesExaflowMalformedRequestThrough() { + var exaflowBody = new StringBuilder("Request malformed:\nbody.inputdata: Field required"); + + assertThat(AnalysisService.convertResponseToAnalysisResult(new Logger("user", "test"), 422, exaflowBody)) + .isEqualTo(Map.of("data", exaflowBody.toString(), "type", "text/plain+error")); + } }