הדף הזה רלוונטי ל-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, התנאי מחזיר true ולכן המשתנהassertcondition.MyAssertCondition.truthValueמוגדר כ-true. - אבל אם הערך של המשתנה
google.dialogflow.my-prefix.claimAmountהוא 1200, המשתנהassertcondition.MyAssertCondition.truthValueמוגדר כ-false.
לרכיב הזה יש את המאפיינים הבאים שמשותפים לכל המדיניות:
| מאפיין | ברירת מחדל | חובה? | תיאור |
|---|---|---|---|
name |
לא רלוונטי | חובה |
השם הפנימי של המדיניות. הערך של מאפיין אפשר להשתמש ברכיב |
continueOnError |
FALSE | אופציונלי | מגדירים את הערך false כדי להחזיר שגיאה אם המדיניות נכשלת. זו התנהגות צפויה ברוב המקרים. הגדרה ל-true מאפשרת להמשיך את הביצוע של התהליך גם אחרי שמדיניות נכשלת. מאמרים קשורים:
|
enabled |
TRUE | אופציונלי | מגדירים את המדיניות למצב true כדי לאכוף אותה. מגדירים את הערך false כדי להשבית את המדיניות. המדיניות לא תיאכף גם אם היא תישאר מצורפת לזרימה. |
async |
FALSE | הוצא משימוש | המאפיין הזה הוצא משימוש. |
הפניה לרכיב צאצא
בקטע הזה מתוארים רכיבי הבן של<AssertCondition>.
<Condition>
מציינים את התנאי להערכה. מידע נוסף על כתיבת הצהרת תנאי ב-Apigee זמין במאמר הפניה לתנאים.
| ערך ברירת המחדל | לא רלוונטי |
| חובה? | חובה |
| סוג | String |
| רכיב אב |
<AssertCondition>
|
| רכיבי צאצא | ללא |
<DisplayName>
אפשר להשתמש במאפיין הזה בנוסף למאפיין name כדי לתת למדיניות שם אחר, שנשמע יותר טבעי, ב-UI של ניהול עריכת ה-proxy.
הרכיב <DisplayName> משותף לכל סוגי המדיניות.
| ערך ברירת המחדל | לא רלוונטי |
| חובה? | זה שינוי אופציונלי. אם לא מציינים את <DisplayName>, המערכת משתמשת בערך של מאפיין name של המדיניות. |
| סוג | String |
| רכיב אב | <PolicyElement> |
| רכיבי צאצא | ללא |
רכיב <DisplayName> משתמש בתחביר הבא:
תחביר
<PolicyElement> <DisplayName>POLICY_DISPLAY_NAME</DisplayName> ... </PolicyElement>
דוגמה
<PolicyElement> <DisplayName>My Validation Policy</DisplayName> </PolicyElement>
לרכיב <DisplayName> אין מאפיינים או רכיבי צאצא.
קודי שגיאה
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 |