Preface

Recently, I am deploying a gateway system based on kong. The default errors of kong and the prompts returned by plug-ins in kong do not conform to the development unified specification.

By consulting the official documents and the official Github issue, it is found that only modifying the kong lua source code can meet the development needs

Tips: Response Transformer Plugins cannot meet development needs

Version

Kong Version: 5.1

Deployment method

  1. docker-compose
  2. Map the modified kong lua dir via volumes
    volumes:
    \- ./kong:/usr/local/share/lua/5.1/kong/  

accomplish

Gateway error prompt field

file: /usr/local/share/lua/5.1/kong/tools/utils.lua

line: 1105 ~ 1130

The error prompt field returned by default is message

{"message": "some error tips"}

Need to change message to error

{"error": "some error tips"}

Route does not exist error message

file1: /usr/local/share/lua/5.1/kong/runloop/handler.lua
line: 1096

file2: /usr/local/share/lua/5.1/kong/plugins/acme/api.lua
line: 78

return by default

{
   "message": "no Route matched with those values"
}

change into

message has been changed to error in the previous step

{
   "error": "Route not found"
}

Conclusion

There are also some tips for plug-ins, which will not be discussed here, and can be adjusted according to needs.

点赞(0)

评论列表 共有 0 评论

暂无评论

微信服务号

微信客服

淘宝店铺

support@elephdev.com

发表
评论
Go
顶部