tzssangglass commented on a change in pull request #5923:
URL: https://github.com/apache/apisix/pull/5923#discussion_r775936726



##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -104,8 +108,31 @@ function _M.access(conf, ctx)
         return 503
     end
 
+    -- parse OpenWhisk JSON response
+    -- OpenWhisk supports two types of responses, the user can return only
+    -- the response body, or set the status code and header.
+    local result, err = core.json.decode(res.body)
+
+    if not result or err then
+        core.log.error("failed to parse openwhisk response data: ", err)
+        return 503
+    end
+
     -- setting response headers
-    core.response.set_header(res.headers)
+    if result.headers ~= nil then
+        core.response.set_header(result.headers)
+    end
+
+    if result.statusCode ~= nil and result.body ~= nil then

Review comment:
       we can use `local code = result.statusCode` and `local body = 
result.body`, and then use `code` and `body`

##########
File path: apisix/plugins/openwhisk.lua
##########
@@ -104,8 +108,31 @@ function _M.access(conf, ctx)
         return 503
     end
 
+    -- parse OpenWhisk JSON response
+    -- OpenWhisk supports two types of responses, the user can return only
+    -- the response body, or set the status code and header.
+    local result, err = core.json.decode(res.body)

Review comment:
       should check the `res.body` is not nil?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to