Skip to main content

Module exit_transformer

Module exit_transformer 

Source
Expand description

The exit-transformer node — reshapes gateway-generated responses (“exits”) with a status-code remap and a body template. Reinterpreted subset of APISIX’s exit-transformer plugin (response-phase: place after upstream, before client).

§Which exits it applies to

By default the node acts only on responses whose context carries an error record (Context.errors non-empty) — a failed upstream, a failed auth callout, an error-handler-rendered body. A deliberate rejection that left its node on an outcome port (denied, limited, broken, abort, redirect, …) carries no error record and is therefore not transformed unless always: true is set.

So to reshape denials and throttles, set always: true and put the node on the path the outcome port takes:

nodes:
  - id: shape-exits
    type: exit-transformer
    config:
      always: true                 # required: a denial carries no error record
      status_map: { "401": 403 }
      body: '{"status": $status, "path": "$uri"}'
edges:
  - from: auth.denied
    to: shape-exits.in             # not straight to client
  - from: shape-exits.success
    to: client.in

With always: true the node transforms every response reaching it, clean upstream replies included — so give it its own branch as above rather than putting it on the main success path.

This is a deliberate reinterpretation, not a faithful port. APISIX’s plugin registers user-supplied Lua functions that receive (code, body, headers) and return replacements. Arbitrary scripted transformation belongs to featherbit’s script node; this node keeps the declarative core of the idea:

  • status_map remaps exit status codes (e.g. hide a 502 as a 503), and
  • body renders a {{namespace.path}} template (plus legacy $var interpolation, including $status) as the new body,

applied only to responses the gateway itself generated (heuristic: Context.errors non-empty), or unconditionally with always: true.

Structs§

ExitTransformerPlugin
Remaps Context.response.status_code via status_map and/or replaces the body with an interpolated {{namespace.path}} (plus legacy $var) template — but only when the response was generated by the gateway (Context.errors non-empty), unless always is set. This plugin never fails at execution time.

Functions§

parse_status 🔒
Validates one status code (map key or value): an integer within 100-599.