{"fault":{"detail":{"errorcode":"steps.extractvariables.SourceMessageNotAvailable"},"faultstring":"mymessage message is not available for ExtractVariable: ParseJsonResponse"}}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[[["\u003cp\u003eThis content explains how policy errors are structured in Apigee and Apigee hybrid, including the system-generated error messages that contain \u003ccode\u003eerrorcode\u003c/code\u003e and \u003ccode\u003efaultstring\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eWhen a policy error occurs, Apigee sets specific flow variables, such as \u003ccode\u003efault.name\u003c/code\u003e (the error name) and \u003ccode\u003e[prefix].[policy_name].failed\u003c/code\u003e (a flag indicating whether a policy failed), which are crucial for fault handling.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eerrorcode\u003c/code\u003e is composed of a prefix and an error name (e.g., \u003ccode\u003esteps.extractvariables.SourceMessageNotAvailable\u003c/code\u003e), where the prefix identifies the type of policy that generated the error.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eerror\u003c/code\u003e and \u003ccode\u003emessage\u003c/code\u003e variables, available in the error flow, provide details about the error, including the error message and status code, and can be used to customize error responses.\u003c/p\u003e\n"],["\u003cp\u003eUnderstanding the structure of policy error responses and how they utilize flow variables enables developers to effectively design and implement custom fault handling mechanisms in their Apigee proxies.\u003c/p\u003e\n"]]],[],null,["# What you need to know about policy errors\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nThis topic describes the structure of policy errors and the kinds of flow variables that are\nset when a policy error occurs. This information is essential if you're designing and\nimplementing fault handling for your proxies.\n\nThis topic assumes you have a general understanding of how fault handling works in\nApigee, and\nthat you know what fault rules are. If you need a review, see\n[Handling faults](/apigee/docs/api-platform/fundamentals/fault-handling). The\ninformation here will\nalso help you navigate and use the [Policy error reference](/apigee/docs/api-platform/reference/policies/error-code-reference).\n\nAbout the default policy error response\n---------------------------------------\n\nWhen a policy throws an error, Apigee immediately enters the error flow and generates an error\nmessage. This system-generated message is a JSON object that includes two bits of information: an\n`errorcode` and a `faultstring`.\n| **Note:** It's helpful to know that in the parts of an error as shown below are available as flow variables. You can restructure and customize error messages through these variables. The variable `fault.name` is the value of the `errorcode` attribute and `error.message` is the value of the `faultstring` attribute. These variables are discussed in more detail in the following sections of this topic.\n\nFor example: \n\n```gdscript\n{\n \"fault\":{\n \"detail\":{\n \"errorcode\":\"steps.extractvariables.SourceMessageNotAvailable\"\n },\n \"faultstring\":\"mymessage message is not available for ExtractVariable: ParseJsonResponse\"\n }\n}\n```\n\nLet's quickly deconstruct this error message:\n\nThe `errorcode` consists of a `prefix` and an `error\nname`, as follows: `[prefix].[error_name]`. In the above example\n\"`steps.extractvariables` is the prefix and `SourceMessageNotAvailable` is\nthe error name. The prefix tells you what kind of policy generated the error. In the above\nexample, you can tell that an [ExtractVariables policy](/apigee/docs/api-platform/reference/policies/extract-variables-policy) generated the error and the error name is\n`SourceMessageNotAvailable`.\n\nThe `faultstring` contains a description of the error. The fault string\ntypically includes clues to help you find the specific problem that caused the error, such as the\nname of the policy, the name of an unresolved variable, or whatever contributed to the error. For\nexample, in the above error message, `mymessage` happens to be the name of an unresolved\nmessage variable referenced in the policy and `ParseJsonResponse` is the name of the\npolicy that triggered the error.\n| **Note:** In the [Policy error reference](/apigee/docs/api-platform/reference/policies/error-code-reference), we use a consistent convention to document policy fault strings. We indicate where place variables occur with a `[]` notation. Here's an example of how we'd document the above error's fault string: \n|\n| ```scdoc\n| VAR_NAME message is not available for ExtractVariable: POLICY_NAME\n| ```\n\nVariables specific to policy errors\n-----------------------------------\n\nWhen a policy error is triggered, certain error-specific flow variables are populated. These\nvariables are extremely useful in fault handling. As explained in\n[Handling faults](/apigee/docs/api-platform/fundamentals/fault-handling), it's a common practice to\ntrap the system-generated policy errors and perform a subsequent action such as to create a\ncustom error response. For example, for security reasons, you might want to prevent clients from\nseeing the actual errors and status codes that Apigee returns.\n\n### The `fault.name` variable\n\nWhen a policy throws an error, it sets the flow variable `fault.name` to the\n`error_name` part of the errorcode (as described in the previous section). It's very\ncommon to evaluate this variable to conditionally execute fault rules.\n\nHere's an example fault rule that tests for the value of `fault.name`: \n\n```text\n\u003cfaultrule name=\"VariableOfNonMsgType\"\u003e\u003c/faultrule\u003e\u003cFaultRule name=\"Source Message Not Available Fault\"\u003e\n \u003cStep\u003e\n \u003cName\u003eAM-CustomErrorMessage\u003c/Name\u003e\n \u003cCondition\u003e(fault.name Matches \"SourceMessageNotAvailable\") \u003c/Condition\u003e\n \u003c/Step\u003e\n\u003c/FaultRule\u003e\n```\n\nThe thing to remember is that when a policy triggers an error, the `fault.name`\nvariable is always set to the error name.\n| **Note:** When you're developing your fault handling code, just look in the [Policy error reference](/apigee/docs/api-platform/reference/policies/error-code-reference) to learn what the error name is for every policy error. It's also a common practice to use [Debug tool](/apigee/docs/api-platform/debug/trace-overview) to examine error responses and the variables that are set.\n\n### The\n`[prefix].[policy_name].failed` variable\n\nBesides `fault.name`, another variable that developers commonly check is the\n`[prefix].[policy_name].failed` flag, which is set to either true or false when a\npolicy executes. In fault rules, you'll want to check to see when it's **true** ---\nthat is, to check if an error occurred. Here's how to construct a conditional that checks the\n`[prefix].[policy_name].failed` flag. To correctly check this variable, you need to\nknow two things:\n\n- The *name* of the policy you are checking. This is the value of the policy's name attribute, not the display name. This attribute is always included in the policy definition's XML.\n- A *prefix* that is specific to the type of policy you are checking. (We'll explain how to find the prefix below.)\n\nTo illustrate, here's another fault rule example. Notice in the outer condition how the\n`[prefix].[policy_name].failed` variable name is formed. In this case the prefix is\n`extractvariables` and the policy name is `ParseJsonResponse`. In this\ncase, the fault rule will only execute if this variable is true. And, here's a tip: because fault\nrules can contain multiple steps, this pattern is a nice way to organize fault rules into\nblocks. \n\n```gdscript\n\u003cfaultrule name=\"VariableOfNonMsgType\"\u003e\u003c/faultrule\u003e\u003cFaultRule name=\"Extract Variable Faults\"\u003e\n \u003cStep\u003e\n \u003cName\u003eAM-CustomErrorMessage\u003c/Name\u003e\n \u003cCondition\u003e(fault.name Matches \"SourceMessageNotAvailable\") \u003c/Condition\u003e\n \u003c/Step\u003e\n \u003cCondition\u003e(extractvariables.ParseJsonResponse.failed = true) \u003c/Condition\u003e\n\u003c/FaultRule\u003e\n```\n| **Note:** How do you know what the fault variable's prefix is? You can't necessarily guess it from the contents of the fault string or error code. You have to look it up in the [Policy error reference](/apigee/docs/api-platform/reference/policies/error-code-reference) or you can use trace to inspect the flow variables that are created when an error occurs. For example, for the Extract Variables policy, the `[prefix].[policy_name].failed` prefix is `extractvariables`, and that's pretty straightforward. But for the Access Control policy, the prefix is `acl`. So, the point is, you have to check.\n\n### **About the\n`error` and `message` variables**\n\nThe `error` variable is only available in the error flow of a\nproxy. You can get useful information from the `error` variable, such as the error message, status\ncode, and so on. The formatting pattern for the error variable is the following: \n\n```scdoc\nerror.ERROR_COMPONENT = VALUE\n```\n\nFor example: \n\n```text\nerror.message = \"request message is not available for ExtractVariable:\n ParseJsonResponse\"\n```\n\nand \n\n```text\nerror.status.code = \"500\"\n```\n| **Tip:** You can also use this variable to set response headers. This can be extremely useful because in the error flow, the response object is not available.\n\nThe `message` variable is also available in the error flow and can be used for\nsimilar purposes as the `error` variable. The message variable is special because it\nis contextual. In a request flow, it behaves like a request variable, and in a response flow, it\ncan be used to get/set response values.\n\nRefer to [Flow variables reference](/apigee/docs/api-platform/reference/variables-reference)\nfor information on all of the Apigee variables, including `error` and\n`message`."]]