error-handler
Overwrites context.response with a configured status code and a body rendered from a template. It is typically wired to the error ports of other nodes (upstream, auth plugins, rate-limit, ...) so failed requests produce a controlled response instead of the raw error.
Configuration
All keys are optional; the constructor never fails.
| Key | Type | Default | Description |
|---|---|---|---|
status_code | integer | 500 | HTTP status of the error response. |
body_template | string | {"error": "internal_error", "message": "An unexpected error occurred"} | Response body. May reference the most recent entry in context.errors through placeholders. |
Supported placeholders, substituted at execution time from the last error in context.errors:
{{error.code}}— the error code (e.g.UPSTREAM_CONNECTION_ERROR,RATE_LIMITED){{error.message}}— the human-readable error message{{error.node_id}}— the id of the node that raised the error
type: error-handler
config:
status_code: 502
body_template: '{"error": "{{error.code}}", "message": "{{error.message}}"}'
Behavior
On execution the plugin:
- Renders
body_template, replacing the placeholders with fields fromcontext.errors.last(). If the errors list is empty, the template is emitted verbatim (placeholders included). - Sets
context.response.status_codeto the configured value, replaces the response body with the rendered template, and forces thecontent-typeresponse header toapplication/json.
It always succeeds and exits through the success port — the error port is never taken, and no error codes are emitted. It reads context.errors but never appends to it, and does not touch context.request or context.message.
UI editor note: the node inspector form offers a content_type field, but the plugin does not read that key — the response content type is always application/json.