Skip to content

Commit 6aa2ba3

Browse files
fix(ai-prompt-*): handle nil err in JSON body parse path (#13314)
1 parent 4762c33 commit 6aa2ba3

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

apisix/core/request.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ function _M.get_json_request_body_table()
343343

344344
local body_tab, err = json.decode(body)
345345
if not body_tab then
346-
return nil, { message = "could not parse JSON request body: " .. err }
346+
return nil, { message = "could not parse JSON request body: " .. (err or "invalid JSON") }
347347
end
348348

349349
return body_tab

apisix/plugins/ai-prompt-decorator.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ end
6767
local function get_request_body_table()
6868
local body, err = core.request.get_body()
6969
if not body then
70-
return nil, { message = "could not get body: " .. err }
70+
return nil, { message = "could not get body: " .. (err or "request body is empty") }
7171
end
7272

7373
local body_tab, err = core.json.decode(body)
7474
if not body_tab then
75-
return nil, { message = "could not parse JSON request body: " .. err }
75+
return nil, { message = "could not parse JSON request body: " .. (err or "invalid JSON") }
7676
end
7777

7878
return body_tab

apisix/plugins/ai-prompt-template.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ end
9393
local function get_request_body_table()
9494
local body, err = core.request.get_body()
9595
if not body then
96-
return nil, { message = "could not get body: " .. err }
96+
return nil, { message = "could not get body: " .. (err or "request body is empty") }
9797
end
9898

9999
local body_tab, err = core.json.decode(body)
100100
if not body_tab then
101-
return nil, { message = "could not parse JSON request body: " .. err }
101+
return nil, { message = "could not parse JSON request body: " .. (err or "invalid JSON") }
102102
end
103103

104104
return body_tab

0 commit comments

Comments
 (0)