Questa pagina si applica ad Apigee e Apigee hybrid.
Visualizza la documentazione di
Apigee Edge.
La policy AssertCondition valuta un'istruzione condizionale in fase di runtime nei flussi di richiesta o risposta. Puoi definire una condizione in base alle variabili di flusso e utilizzare questo criterio per verificarla. Una condizione restituisce sempre un valore booleano, vero o falso. Per saperne di più sulla scrittura di un'istruzione condizionale, consulta Guida di riferimento alle condizioni.
Dopo aver valutato la condizione, il criterio AssertCondition memorizza il risultato della
valutazione nella variabile di flusso assertcondition.policy-name.truthValue.
Puoi utilizzare la variabile di flusso risultante nei callout o nella logica orchestrata successivi.
Se una condizione restituisce il valore true, il valore della variabile viene impostato su
true, altrimenti su false. Se hai definito più criteri
AssertCondition, policy-name nel
nome della variabile ti aiuta a identificarla in modo univoco.
Questa policy è una policy standard e può essere implementata in qualsiasi tipo di ambiente. Per informazioni sui tipi di policy e sulla disponibilità con ogni tipo di ambiente, consulta Tipi di policy.
<AssertCondition>
Definisce una policy <AssertCondition>. Utilizzando questo criterio, puoi valutare un'istruzione condizionale con una o più condizioni unite da un operatore logico. Per informazioni
su tutti gli operatori supportati in una condizione, vedi Operatori.
true o false.
| Valore predefinito | N/D |
| Obbligatorio? | Obbligatorio |
| Tipo | Tipo complesso |
| Elemento principale | N/D |
| Elementi secondari |
<Condition><DisplayName> |
La tabella seguente fornisce una descrizione generale degli elementi secondari di <AssertCondition>:
| Elemento secondario | Obbligatorio? | Descrizione |
|---|---|---|
<Condition> |
Sì | Specifica la condizione da valutare. |
<DisplayName> |
Facoltativo | Un nome personalizzato per il criterio. |
L'elemento <AssertCondition> utilizza la seguente sintassi:
Sintassi
<?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>Esempio
L'esempio seguente controlla se la variabile google.dialogflow.my-prefix.claimAmount è maggiore
di 0 e inferiore a 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>In questo esempio:
- Se il valore della variabile
google.dialogflow.my-prefix.claimAmountè 500, la condizione restituisce true e quindi la variabileassertcondition.MyAssertCondition.truthValueè impostata sutrue. - Tuttavia, se il valore della variabile
google.dialogflow.my-prefix.claimAmountè 1200, la variabileassertcondition.MyAssertCondition.truthValueè impostata sufalse.
此元素具有所有政策中常见的以下属性:
| 属性 | 默认 | 是否必需? | 说明 |
|---|---|---|---|
name |
不适用 | 必需 |
政策的内部名称。 (可选)使用 |
continueOnError |
false | 可选 | 设置为 false 可在政策失败时返回错误。这是大多数政策的预期行为。设置为 true,即使在政策失败后,仍可以继续执行流。另请参阅:
|
enabled |
true | 可选 | 设置为 true 可实施政策。 设为 false 可关闭政策。即使政策仍附加到某个流,也不会强制执行该政策。 |
async |
false | 已弃用 | 此属性已弃用。 |
Riferimento all'elemento secondario
Questa sezione descrive gli elementi secondari di<AssertCondition>.
<Condition>
Specifica la condizione da valutare. Per saperne di più sulla scrittura di un'istruzione condizionale in Apigee, consulta Riferimento alle condizioni.
| Valore predefinito | N/D |
| Obbligatorio? | Obbligatorio |
| Tipo | Stringa |
| Elemento principale |
<AssertCondition>
|
| Elementi secondari | Nessuno |
<DisplayName>
除了用于 name 属性之外,还可用于在管理界面代理编辑器中使用其他更加自然的名称标记政策。
<DisplayName> 元素适用于所有政策。
| 默认值 | 不适用 |
| 是否必需? | 可选。如果省略 <DisplayName>,则会使用政策的 name 属性的值 |
| 类型 | 字符串 |
| 父元素 | <PolicyElement> |
| 子元素 | 无 |
<DisplayName> 元素使用以下语法:
语法
<PolicyElement> <DisplayName>POLICY_DISPLAY_NAME</DisplayName> ... </PolicyElement>
示例
<PolicyElement> <DisplayName>My Validation Policy</DisplayName> </PolicyElement>
<DisplayName> 元素没有属性或子元素。
Codici di errore
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 |