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
- docker-compose
- 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 toerror
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.
Post comment 取消回复