이 페이지는 Apigee 및 Apigee Hybrid에 적용됩니다.
Apigee Edge 문서 보기
개요
AssertCondition 정책은 요청 또는 응답 흐름에서 조건부 문을 평가합니다. 흐름 변수를 기반으로 조건을 정의하고 이 정책을 사용하여 조건을 어설션할 수 있습니다. 조건은 항상 부울 값(true 또는 false)으로 평가됩니다. 조건문 작성에 대한 자세한 내용은 조건 참조를 확인하세요.
조건을 평가한 후 AssertCondition 정책은 assertcondition.policy-name.truthValue 흐름 변수에 평가 결과를 저장합니다.
후속 콜아웃 또는 조정된 로직에서 결과 흐름 변수를 사용할 수 있습니다.
조건이 true로 평가되면 변수 값이 true로 설정되고 그렇지 않으면 false로 설정됩니다. 여러 AssertCondition 정책을 정의한 경우 변수 이름의 policy-name을 통해 변수를 고유하게 식별할 수 있습니다.
이 정책은 표준 정책이며 모든 환경 유형에 배포할 수 있습니다. 정책 유형과 각 환경 유형에서의 가용성에 대한 자세한 내용은 정책 유형을 참조하세요.
<AssertCondition>
<AssertCondition> 정책을 정의합니다. 이 정책을 사용하면 논리 연산자로 연결된 하나 이상의 조건이 있는 조건문을 평가할 수 있습니다. 조건에서 지원되는 모든 연산자에 대한 자세한 내용은 연산자를 참조하세요.
true 또는 false일 수 있는 부울 값입니다.
| 기본값 | 해당 사항 없음 |
| 필수 여부 | 필수 |
| 유형 | 복합 유형 |
| 상위 요소 | 해당 사항 없음 |
| 하위 요소 |
<Condition><DisplayName> |
다음 표에서는 <AssertCondition>의 하위 요소를 간략하게 설명합니다.
| 하위 요소 | 필수 여부 | 설명 |
|---|---|---|
<Condition> |
예 | 평가할 조건을 지정합니다. |
<DisplayName> |
선택사항 | 정책의 커스텀 이름입니다. |
<AssertCondition> 요소는 다음 구문을 사용합니다.
구문
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition">
<!-- Display name for this policy -->
<DisplayName>DISPLAY_NAME</DisplayName>
<!-- Assertion's condition where operators are defined -->
<Condition>CONDITIONAL_STATEMENT</Condition>
</AssertCondition>예
다음 예시에서는 google.dialogflow.my-prefix.claimAmount 변수가 0보다 크고 1000보다 작은지 확인합니다.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssertCondition continueOnError="false" enabled="true"
name="MyAssertCondition">
<DisplayName>Assert My Condition</DisplayName>
<Condition>(google.dialogflow.my-prefix.claimAmount > 0)
and
(google.dialogflow.my-prefix.claimAmount LesserThan 1000)</Condition>
</AssertCondition>예를 들면 다음과 같습니다.
google.dialogflow.my-prefix.claimAmount변수 값이 500이면 조건이 참으로 평가되므로assertcondition.MyAssertCondition.truthValue변수가true로 설정됩니다.- 그러나
google.dialogflow.my-prefix.claimAmount변수 값이 1200이면assertcondition.MyAssertCondition.truthValue변수는false로 설정됩니다.
This element has the following attributes that are common to all policies:
| Attribute | Default | Required? | Description |
|---|---|---|---|
name |
N/A | Required |
The internal name of the policy. The value of the Optionally, use the |
continueOnError |
false | Optional | Set to false to return an error when a policy fails. This is expected behavior for
most policies. Set to true to have flow execution continue even after a policy
fails. See also:
|
enabled |
true | Optional | Set to true to enforce the policy. Set to false to turn off the
policy. The policy will not be enforced even if it remains attached to a flow. |
async |
false | Deprecated | This attribute is deprecated. |
하위 요소 참조
이 섹션에서는<AssertCondition>의 하위 요소를 설명합니다.
<Condition>
평가할 조건을 지정합니다. Apigee에서 조건문을 작성하는 방법에 대한 자세한 내용은 조건 참조를 확인하세요.
| 기본값 | 해당 사항 없음 |
| 필수 여부 | 필수 |
| 유형 | 문자열 |
| 상위 요소 |
<AssertCondition>
|
| 하위 요소 | 없음 |
<DisplayName>
Use in addition to the name attribute to label the policy in the
management UI proxy editor with a different, more natural-sounding name.
The <DisplayName> element is common to all policies.
| Default Value | N/A |
| Required? | Optional. If you omit <DisplayName>, the value of the
policy's name attribute is used. |
| Type | String |
| Parent Element | <PolicyElement> |
| Child Elements | None |
The <DisplayName> element uses the following syntax:
Syntax
<PolicyElement> <DisplayName>POLICY_DISPLAY_NAME</DisplayName> ... </PolicyElement>
Example
<PolicyElement> <DisplayName>My Validation Policy</DisplayName> </PolicyElement>
The <DisplayName> element has no attributes or child elements.
오류 코드
This section describes the fault codes and error messages that are returned and fault variables that are set by Apigee when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.
Runtime errors
These errors can occur when the policy executes.
| Fault code | HTTP status | Cause |
|---|---|---|
steps.assertcondition.ConditionEvaluationFailed |
500 |
Failed to evaluate the conditional statement. There can be many reasons for this error, including incorrect values in the variables at run time. |
Deployment errors
These errors can occur when you deploy a proxy containing this policy.
| Error name | Cause |
|---|---|
InvalidCondition |
The policy was not able to validate the conditional statement. There can be many reasons for this error, including malformed conditions or use of unsupported operators. |
Fault variables
Whenever there are execution errors in a policy, Apigee generates error messages. You can view these error messages in the error response. Many a time, system generated error messages might not be relevant in the context of your product. You might want to customize the error messages based on the type of error to make the messages more meaningful.
To customize the error messages, you can use either fault rules or the RaiseFault policy. For
information about differences between fault rules and the RaiseFault policy, see
FaultRules vs. the RaiseFault policy.
You must check for conditions using the Condition element in both the fault rules and the RaiseFault policy.
Apigee provides fault variables unique to each policy and the values of the fault variables are set when a policy triggers runtime errors.
By using these variables, you can check for specific error conditions and take appropriate actions. For more information about checking error
conditions, see Building conditions.
The following table describes the fault variables specific to this policy.
| Variables | Where | Example |
|---|---|---|
fault.name="FAULT_NAME" |
FAULT_NAME is the name of the fault, as listed in the Runtime errors table. The fault name is the last part of the fault code. | fault.name Matches "ConditionEvaluationFailed" |
AssertCondition.POLICY_NAME.failed |
POLICY_NAME is the user-specified name of the policy that threw the fault. | AssertCondition.My-AssertCondition.failed = true |