添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kong:2.4.0
I'm developing a plugin for kong and got a problem.Here is the code:

local error = error
local ERROR = "error"
local kong = kong
local _M = {}
local funtion do_authentication(conf)
    if not kong.request.get_header("token") then
        return nil,{
            status = 401,
            message = {
                [ERROR] = "invalid_request",
                error_description = "The token is missing"
           headers = {
               ["WWW-Authenticate"] = "example"
fuction _M.execute(conf)
    local ok,err = do_authentication(conf)
    if not ok then
        return kong.response.error(err.status, err.message, err.headers)
return _M

When I test it ,I got a unexception error,and the error log is message must be a nil or a string, I change the message to a string and run success.
but in the pdk source code 981 I found the message can use table so what's wrong with my code?

Hello, could it be that you forgot to add a return true to do_authentication? Otherwise, if the expected header is passed, the function will return nil, nil, provoking an error log similar to the one you are getting.

If that's not it, could you please provide us with a more detailed trace of the error?

Hello, could it be that you forgot to add a return true to do_authentication? Otherwise, if the expected header is passed, the function will return nil, nil, provoking an error log similar to the one you are getting.

If that's not it, could you please provide us with a more detailed trace of the error?

I just test the condition of token missing.
And here is the log

2021/05/10 15:27:34 [error] 26574#0: *3913 [kong] init.lua:271 [sso] /data/code/kong-plugin-sso/kong/plugins/sso/handler.lua:9: message must be a nil or a string, client: 10.132.106.37, server: kong, request: "GET /RdTestLoginService/actuator/health HTTP/1.1", host: "10.114.205.170:8000"

and the handle.lua :

local access = require "kong.plugins.sso.access"
local SSOHandler = {PRIORITY = 1000,VERSION="1.0.0"}
funtion SSOHandler:access(conf)
    access.excute(conf)
return SSOHandler

and I try to use cjson format the table to string :

fuction _M.execute(conf)
    local ok,err = do_authentication(conf)
    if not ok then
         local jsonMessage,jsonError = cjson.encode(err.massage)
        return kong.response.error(err.status, jsonMessage, err.headers)

It work fine.

Hi @FaustPipeDream!

The support for the "table" type message in kong.response.error() will be part of the next Kong release. The code you mentioned is in the master branch but is not part of Kong 2.4.0 (or even 2.4.1, FWIW). If you check Kong 2.4.0, kong.response.error() doesn't handle tables: https://github.com/Kong/kong/blob/2.4.0/kong/pdk/response.lua#L984

As this is an actual issue but already fixed, I'm closing this ticket. Thanks for your report!