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

shreemaan-abhishek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 6aa2ba3fd fix(ai-prompt-*): handle nil err in JSON body parse path 
(#13314)
6aa2ba3fd is described below

commit 6aa2ba3fd4dafb7166f34b9f7254c81d4f48e86d
Author: Shreemaan Abhishek <[email protected]>
AuthorDate: Thu Apr 30 12:44:34 2026 +0800

    fix(ai-prompt-*): handle nil err in JSON body parse path (#13314)
---
 apisix/core/request.lua                | 2 +-
 apisix/plugins/ai-prompt-decorator.lua | 4 ++--
 apisix/plugins/ai-prompt-template.lua  | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/apisix/core/request.lua b/apisix/core/request.lua
index 3db323d48..f49f648ab 100644
--- a/apisix/core/request.lua
+++ b/apisix/core/request.lua
@@ -343,7 +343,7 @@ function _M.get_json_request_body_table()
 
     local body_tab, err = json.decode(body)
     if not body_tab then
-        return nil, { message = "could not parse JSON request body: " .. err }
+        return nil, { message = "could not parse JSON request body: " .. (err 
or "invalid JSON") }
     end
 
     return body_tab
diff --git a/apisix/plugins/ai-prompt-decorator.lua 
b/apisix/plugins/ai-prompt-decorator.lua
index 800846e2a..ba9cbe6a5 100644
--- a/apisix/plugins/ai-prompt-decorator.lua
+++ b/apisix/plugins/ai-prompt-decorator.lua
@@ -67,12 +67,12 @@ end
 local function get_request_body_table()
     local body, err = core.request.get_body()
     if not body then
-        return nil, { message = "could not get body: " .. err }
+        return nil, { message = "could not get body: " .. (err or "request 
body is empty") }
     end
 
     local body_tab, err = core.json.decode(body)
     if not body_tab then
-        return nil, { message = "could not parse JSON request body: " .. err }
+        return nil, { message = "could not parse JSON request body: " .. (err 
or "invalid JSON") }
     end
 
     return body_tab
diff --git a/apisix/plugins/ai-prompt-template.lua 
b/apisix/plugins/ai-prompt-template.lua
index 8ca0eaf8f..0fe47617e 100644
--- a/apisix/plugins/ai-prompt-template.lua
+++ b/apisix/plugins/ai-prompt-template.lua
@@ -93,12 +93,12 @@ end
 local function get_request_body_table()
     local body, err = core.request.get_body()
     if not body then
-        return nil, { message = "could not get body: " .. err }
+        return nil, { message = "could not get body: " .. (err or "request 
body is empty") }
     end
 
     local body_tab, err = core.json.decode(body)
     if not body_tab then
-        return nil, { message = "could not parse JSON request body: " .. err }
+        return nil, { message = "could not parse JSON request body: " .. (err 
or "invalid JSON") }
     end
 
     return body_tab

Reply via email to