pantsel / kong-middleman-plugin

A Kong plugin that enables you to make an extra HTTP POST request before calling an API.
MIT License
156 stars 63 forks source link

json.lua:685: nil passed to JSON:decode() #23

Open anassolanki opened 4 years ago

anassolanki commented 4 years ago

Can someone help me out to solve this error.

2020/01/31 10:28:31 [error] 2331#0: *1515852 [kong] init.lua:687 /usr/local/share/lua/5.1/kong/plugins/middleman/json.lua:685: nil passed to JSON:decode(), client: 127.0.0.1, server: kong, request

apurvajain commented 4 years ago

This error occurs when you target service isn't running properly. Test your POST call to specified url with request body and response type is a lua table (JSON):

curl -X POST http://kong:8001/apis/{api}/plugins \
    --data "name=middleman" \
    --data "config.url=http://myserver.io/validate"
    --data "config.response=table"
    --data "config.timeout=10000"
    --data "config.keepalive=60000"

If still facing this issue go to json.lua line no. 984 function OBJDEF:decode(text, etc, options) add the below lines to avoid the error temporarily:

if text == nil then
   text = ''
end
anassolanki commented 4 years ago

Hello, my target service is running fine @apurvajain. I am adding the condition you have given. Is there any problem if we get that 'nill' error?

abdulrazakbg commented 2 years ago

@anassolanki I am also getting the same error while calling api deployed on k8s but its working fine if I connected to local spring boot application API. have you got any solution for above issues ?