Skip to content

Commit

Permalink
fix: add policy result key to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ytvnr committed Jun 27, 2023
1 parent 237c31a commit f8b6774
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ Some variables are automatically bound to the Groovy script to allow users to us

|===

You can interrupt request or response processing by setting the result state to `FAILURE`, providing an HTTP
status code and a message (this is not mandatory, as the default status is `500 - internal server error`).
Request or response processing can be interrupted by setting the result state to `FAILURE`.
By default, it will throw a `500 - internal server error` but you can override this behavior with the following properties:
- `code`: An HTTP status code
- `error`: The error message
- `key`: The key of a response template

[source, groovy]
----
import io.gravitee.policy.groovy.PolicyResult.State
if (request.headers.containsKey('X-Gravitee-Break')) {
result.key = 'RESPONSE_TEMPLATE_KEY';
result.state = State.FAILURE;
result.code = 500
result.error = 'Stop request processing due to X-Gravitee-Break header'
Expand All @@ -76,6 +80,7 @@ To customize the error sent by the policy:
[source, groovy]
----
import io.gravitee.policy.groovy.PolicyResult.State
result.key = 'RESPONSE_TEMPLATE_KEY';
result.state = State.FAILURE;
result.code = 400
result.error = '{"error":"My specific error message","code":"MY_ERROR_CODE"}'
Expand Down

0 comments on commit f8b6774

Please sign in to comment.