feat(plugin): add error-page plugin#13380
Open
AlinsRan wants to merge 7 commits into
Open
Conversation
The error-page plugin customizes the HTTP error response body and content type for APISIX-generated error responses. It uses plugin metadata for global configuration and intercepts error responses generated by APISIX itself (e.g., no matching route, unreachable upstream), leaving upstream-generated responses unaffected. Key features: - Global on/off switch via `enable` in plugin metadata - Supports any HTTP status code via patternProperties (100-599) - Configurable response body and content-type per status code - Falls back to default nginx/APISIX error page when not configured Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Use response_body_like eval qr// to avoid trailing newline issue with lookahead patterns in Test::Nginx response_body_like blocks - Fix docs/zh/latest/config.json sidebar entry (label is '转换请求') Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The plugin list in apisix/cli/config.lua is the authoritative default plugin list used at runtime. Adding error-page between datadog and lago matches the priority ordering. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The enable flag required users to explicitly set enable=true after configuring error pages, which was redundant and unintuitive. The plugin now intercepts errors as long as a matching error_XXX entry with a non-empty body exists in the metadata. To disable, delete the metadata or remove the plugin from the global rule. Update tests and docs accordingly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
error-page requires metadata configuration to be useful, so it should be opt-in. Keep it in cli/config.lua as a known plugin but comment it out in config.yaml.example and config-default.yaml. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove error-page from the default plugin list in cli/config.lua so the plugin is not loaded unless the user explicitly adds it to their conf/config.yaml. Restore conf2/config-default.yaml - error-page should not appear there at all (not even commented out). Remove error-page from t/admin/plugins.t expected list since it is no longer in the default plugin set. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file does not exist in the upstream apache/apisix repository and should not have been added. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces the
error-pageplugin, which allows customizing the response body and content type for HTTP error responses generated by APISIX itself (e.g., when no route matches or when the upstream is unreachable). Responses from upstream services are not intercepted.Configuration
The plugin is configured via plugin metadata (global config, no per-route attributes needed):
{ "enable": true, "error_404": { "body": "<html><body><h1>404 - Not Found</h1></body></html>", "content_type": "text/html" }, "error_500": { "body": "{\"code\": 500, \"message\": \"Internal Server Error\"}", "content_type": "application/json" } }Key design points
enablein plugin metadatapatternProperties, using keys likeerror_404,error_502, etc.bodyandcontent_typeupstream_statusis not set) are interceptedChanges
apisix/plugins/error-page.lua: plugin implementationconf2/config-default.yaml: register the plugin (priority: 450)conf/config.yaml.example: register the plugin (priority: 450)t/plugin/error-page.t: test casest/admin/plugins.t: add plugin to the expected plugin listdocs/en/latest/plugins/error-page.md: English documentationdocs/zh/latest/plugins/error-page.md: Chinese documentationdocs/en/latest/config.json: add to sidebar under Transformationdocs/zh/latest/config.json: add to sidebar under Transformation