Issue description
Relate to #3528
I think we can add a feature to customize the body when response exits. For example, different format of json, even html
or xml , can be use to display the exit message
Refer to apisix/core/response.lua, resp_exit will be called when response exits, I think it is a global handle for response exiting, we can't use plugin extension here。 What about redirecting to a new uri to do the actual work ?
Add method
function _M.register_exit_handle_uri(uri){
handle_uri = uri
}
Modify apisix/core/response.lua
Add exec to redirect to error handle
if handle_uri then
ngx.exec(handle_uri, {code=xxx, body=yyy});
else
if idx > 0 then
ngx_print(concat_tab(t, "", 1, idx))
end
if code then
return ngx_exit(code)
end
end
Add new config to change this behavior
apisix:
exit_handle_uri:"/error_handle"
New uri for error handle,added by http_server_configuration_snippet
location = /error_handle {
content_by_lua '
local args = ngx.req.get_uri_args()
ngx.print(args.body)
return ngx.exit(args.code)
';
}
Some discussion about kong
1 Kong error response
Kong/kong#3192
2 Upstream error response
Kong/kong#972
Environment
- apisix version (cmd:
apisix version):2.2
- OS (cmd:
uname -a):ubuntu 16
- OpenResty / Nginx version (cmd:
nginx -V or openresty -V): 1.19
- etcd version, if have (cmd: run
curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):3.4.17
- apisix-dashboard version, if have:
Issue description
Relate to #3528
I think we can add a feature to customize the body when response exits. For example, different format of json, even html
or xml , can be use to display the exit message
Refer to apisix/core/response.lua, resp_exit will be called when response exits, I think it is a global handle for response exiting, we can't use plugin extension here。 What about redirecting to a new uri to do the actual work ?
Add method
Modify apisix/core/response.lua
Add exec to redirect to error handle
Add new config to change this behavior
New uri for error handle,added by http_server_configuration_snippet
Some discussion about kong
1 Kong error response
Kong/kong#3192
2 Upstream error response
Kong/kong#972
Environment
apisix version):2.2uname -a):ubuntu 16nginx -Voropenresty -V): 1.19curl http://127.0.0.1:9090/v1/server_infoto get the info from server-info API):3.4.17