This is an automated email from the ASF dual-hosted git repository.

Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 95612fe33e fix: handle null response status in 
AiResponseTransformerTemplate and add corresponding unit test (#6929)
95612fe33e is described below

commit 95612fe33e27cf8101b025ad1005cdfa38747326
Author: Limbo <[email protected]>
AuthorDate: Mon Aug 17 14:34:12 2026 +0800

    fix: handle null response status in AiResponseTransformerTemplate and add 
corresponding unit test (#6929)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../template/AiResponseTransformerTemplate.java    |  6 ++-
 .../AiResponseTransformerTemplateStatusTest.java   | 49 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplate.java
 
b/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplate.java
index 7ec3cbcded..f9119e688c 100644
--- 
a/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplate.java
+++ 
b/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplate.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
 import org.springframework.core.io.buffer.DataBuffer;
 import org.springframework.core.io.buffer.DataBufferUtils;
 import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpStatusCode;
 import org.springframework.http.MediaType;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.web.server.ServerWebExchange;
@@ -187,7 +188,10 @@ public class AiResponseTransformerTemplate {
                     // as the response body is not yet available when the 
template is assembled)
                     ObjectNode responseNode = objectMapper.createObjectNode();
                     responseNode.set("headers", responseHeadersJson);
-                    responseNode.put("status", 
exchange.getResponse().getStatusCode().value());
+                    HttpStatusCode responseStatus = 
exchange.getResponse().getStatusCode();
+                    if (Objects.nonNull(responseStatus)) {
+                        responseNode.put("status", responseStatus.value());
+                    }
                     responseNode.put("body", "");
 
                     rootNode.set("request", requestNode);
diff --git 
a/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/test/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplateStatusTest.java
 
b/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/test/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplateStatusTest.java
new file mode 100644
index 0000000000..4afe9b55e4
--- /dev/null
+++ 
b/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/test/java/org/apache/shenyu/plugin/ai/transformer/response/template/AiResponseTransformerTemplateStatusTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.ai.transformer.response.template;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
+import org.springframework.mock.web.server.MockServerWebExchange;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Test cases for response status handling in {@link 
AiResponseTransformerTemplate}.
+ */
+final class AiResponseTransformerTemplateStatusTest {
+
+    @Test
+    void testAssembleMessageWithoutResponseStatus() throws Exception {
+        MockServerHttpRequest request = 
MockServerHttpRequest.get("/test").build();
+        MockServerWebExchange exchange = MockServerWebExchange.from(request);
+        assertNull(exchange.getResponse().getStatusCode());
+
+        AiResponseTransformerTemplate template = new 
AiResponseTransformerTemplate("Transform this response", request);
+        String message = template.assembleMessage(exchange).block();
+
+        assertNotNull(message);
+        JsonNode responseNode = new 
ObjectMapper().readTree(message).get("response");
+        assertNotNull(responseNode);
+        assertFalse(responseNode.has("status"));
+    }
+}

Reply via email to