Custom response objects for error cases #67
-
I am writing policies which will return custom responses in error cases. I am trying to return the path in error response but I am getting illegal default rule (value cannot contain ref). Please advise how I can send the path in response in error cases.
Input:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Since the purpose of the package envoy.authz
import input.attributes.request.http as http_request
default request_path = ""
request_path = http_request.path
allow = response {
input.attributes.request.http.method == "GET"
response := {
"allowed": true,
"headers": {"x-ext-auth-allow": "yes"}
}
} else = {
"allowed": false,
"headers": {"x-ext-auth-allow": "no"},
"body": {
"message": "Unauthorized Request",
"path": request_path
},
"http_status": 301
} |
Beta Was this translation helpful? Give feedback.
Since the purpose of the
default
keyword is to provide a fallback in case of an undefined value, it would be pretty bad if also the fallback was allowed to be undefined. In your case, you could use anelse
condition, and adefault
value for the path to make sure something is always returned, even when no input is provided with the request.