indrekj commented on issue #11995:
URL: https://github.com/apache/apisix/issues/11995#issuecomment-2685160517
I solved it by writing a custom plugin:
```
- apiVersion: v1
kind: ConfigMap
metadata:
name: apisix-custom-plugins
data:
glia-errors.lua: |
local core = require("apisix.core")
local schema = {
type = "object",
properties = {},
required = {},
}
local _M = {
version = 0.1,
priority = 10,
name = "glia-errors",
schema = schema,
}
function _M.check_schema(conf)
return core.schema.check(schema, conf)
end
local function is_match()
return ngx.status == 429
end
function _M.header_filter(conf, ctx)
if is_match() then
core.response.clear_header_as_body_modified()
end
end
function _M.body_filter(conf, ctx)
if is_match() then
local body = core.response.hold_body_chunk(ctx)
if not body then
return
end
ngx.arg[1] = "<html><head><title>" .. ngx.status .. " " ..
ngx.var.status_text .. "</title></head><body><center><h1>" .. ngx.status .. " "
.. ngx.var.status_text .. "</h1></center></html>\n"
end
end
return _M
```
Note that this is just the preliminary code. It doesn't distinguish between
apisix errors and upstream errors. But for 429 it is fine for us. Also it
doesn't handle other >= 400 errors.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]