Esta página se aplica à Apigee e à Apigee híbrida.
Confira a documentação da
Apigee Edge.
Visão geral
A política AssertCondition avalia uma instrução condicional do ambiente de execução nos fluxos de solicitação ou resposta. É possível definir uma condição com base nas variáveis de fluxo e usar essa política para declarar a condição. Uma condição sempre é avaliada como um valor booleano, verdadeiro ou falso. Para mais informações sobre como escrever uma instrução condicional, consulte Referência de condições.
Depois de avaliar a condição, a política AssertCondition armazena o resultado da
avaliação na variável de fluxo assertcondition.policy-name.truthValue
.
É possível usar a variável de fluxo resultante nas chamadas subsequentes ou na lógica orquestrada.
Se uma condição for avaliada como verdadeira, o valor da variável será definido como
true
. Caso contrário, como false
. Se você definiu várias
políticas AssertCondition, o policy-name
no
nome da variável ajudará a identificá-la de maneira exclusiva.
Esta é uma política padrão e pode ser implantada em qualquer tipo de ambiente. Para informações sobre os tipos de políticas e a disponibilidade de cada tipo de ambiente, consulte Tipos de políticas.
<AssertCondition>
Define uma política <AssertCondition>
. Ao usar essa política, é possível avaliar uma
instrução condicional que tenha uma ou mais condições mescladas por um operador lógico. Para mais informações
sobre todos os operadores compatíveis em uma condição, consulte Operadores.
true
ou um false
.
Valor padrão | N/A |
Obrigatório? | Obrigatório |
Tipo | Tipo complexo |
Elemento pai | N/A |
Elemento filho |
<Condition> <DisplayName> |
A tabela a seguir fornece uma descrição de alto nível dos elementos-filhos de <AssertCondition>
:
Elemento filho | Obrigatório? | Descrição |
---|---|---|
<Condition> |
Sim | Especifica a condição a ser avaliada. |
<DisplayName> |
Opcional | Um nome personalizado para a política. |
O elemento <AssertCondition>
usa a seguinte sintaxe:
Sintaxe
<?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>
Exemplo
O exemplo a seguir verifica se a variável google.dialogflow.my-prefix.claimAmount
é maior
que 0 e menor que 1.000.
<?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>
Neste exemplo:
- Se o valor da variável
google.dialogflow.my-prefix.claimAmount
for 500, a condição será avaliada como verdadeira e, portanto, a variávelassertcondition.MyAssertCondition.truthValue
será definida comotrue
. - No entanto, se o valor da variável
google.dialogflow.my-prefix.claimAmount
for 1200, a variávelassertcondition.MyAssertCondition.truthValue
será definida comofalse
.
Este elemento tem os seguintes atributos comuns a todas as políticas:
Atributo | Padrão | Obrigatório? | Descrição |
---|---|---|---|
name |
N/A | Valor |
O nome interno da política. O valor do atributo Opcionalmente, use o elemento |
continueOnError |
falso | Opcional | Defina como false para retornar um erro quando uma política falhar. Esse é o comportamento esperado para
a maioria das políticas. Defina como true para que a execução do fluxo continue, mesmo depois que uma política
falhar. Consulte também:
|
enabled |
true | Opcional | Defina como true para aplicar a política. Defina como false para desativar a política. A política não será aplicada mesmo que permaneça vinculada a um fluxo. |
async |
falso | Obsoleto | Esse atributo está obsoleto. |
Referência a elementos filhos
Esta seção descreve os elementos filhos de<AssertCondition>
.
<Condition>
Especifica a condição a ser avaliada. Para mais informações sobre como escrever uma instrução condicional na Apigee, consulte Referência de condições.
Valor padrão | N/A |
Obrigatório? | Obrigatório |
Tipo | String |
Elemento pai |
<AssertCondition>
|
Elemento filho | Nenhum |
<DisplayName>
Use em conjunto com o atributo name
para etiquetar a política no editor de proxy da IU de gestão com um nome diferente e mais natural.
O elemento <DisplayName>
é comum a todas as políticas.
Valor predefinido | N/A |
Obrigatório? | Opcional. Se omitir <DisplayName> , é usado o valor do atributo name da política. |
Tipo | String |
Elemento principal | <PolicyElement> |
Elementos subordinados | Nenhum |
O elemento <DisplayName>
usa a seguinte sintaxe:
Sintaxe
<PolicyElement> <DisplayName>POLICY_DISPLAY_NAME</DisplayName> ... </PolicyElement>
Exemplo
<PolicyElement> <DisplayName>My Validation Policy</DisplayName> </PolicyElement>
O elemento <DisplayName>
não tem atributos nem elementos subordinados.
Códigos de erro
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 |