AlinsRan opened a new pull request, #13380:
URL: https://github.com/apache/apisix/pull/13380
## Summary
This PR introduces the `error-page` plugin, 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):
```json
{
"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
- **Global on/off**: controlled by `enable` in plugin metadata
- **Flexible status code support**: supports any HTTP status code (100–599)
via JSON Schema `patternProperties`, using keys like `error_404`, `error_502`,
etc.
- **Custom content-type**: each status code can have its own `body` and
`content_type`
- **Upstream responses unaffected**: only APISIX/nginx-generated error
responses (where `upstream_status` is not set) are intercepted
- **Graceful fallback**: if no custom page is configured for a status code,
the default nginx/APISIX error page is used
## Changes
- `apisix/plugins/error-page.lua`: plugin implementation
- `conf2/config-default.yaml`: register the plugin (priority: 450)
- `conf/config.yaml.example`: register the plugin (priority: 450)
- `t/plugin/error-page.t`: test cases
- `t/admin/plugins.t`: add plugin to the expected plugin list
- `docs/en/latest/plugins/error-page.md`: English documentation
- `docs/zh/latest/plugins/error-page.md`: Chinese documentation
- `docs/en/latest/config.json`: add to sidebar under Transformation
- `docs/zh/latest/config.json`: add to sidebar under Transformation
--
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]