

# 開啟偵錯訊息
<a name="gateway-debug-messages"></a>

當您的閘道正在開發中時，您可以開啟偵錯訊息，以傳回目標組態問題的詳細資訊，包括 lambda 函數錯誤、輸出授權方錯誤、目標規格參數驗證錯誤。開啟偵錯訊息後，如果您叫用閘道時發生問題，回應將傳回訊息以協助您偵錯。

 **若要開啟偵錯訊息，請執行下列其中一項操作：**
+ 如果您使用 AgentCore CLI 建立閘道，偵錯會自動開啟。
+ 如果您使用 AWS 管理主控台建立閘道，預設會開啟偵錯。選項位於**閘道詳細資訊**區段中的**其他組態**下。
+ 如果您使用 AWS CLI 或 AWS SDK，請將值設定為提出 [CreateGateway](https://docs.aws.amazon.com/bedrock-agentcore-control/latest/APIReference/API_CreateGateway.html) 或 [UpdateGateway](https://docs.aws.amazon.com/bedrock-agentcore-control/latest/APIReference/API_UpdateGateway.html) 請求`DEBUG`時`exceptionLevel`的值。

當您完成偵錯閘道時，您可以更新閘道以關閉偵錯訊息，因此傳送給最終使用者的訊息只會顯示未指定的內部錯誤。

 **若要關閉偵錯訊息，請執行下列其中一項操作：**
+ 在 AWS 管理主控台中，當您建立或編輯閘道時，請在**閘道詳細資訊**區段中展開**其他組態**，並取消勾選**例外狀況層級偵錯**旁的核取方塊。
+ 在 AWS CLI 或 AWS SDK 中，當您發出`CreateGateway`或`UpdateGateway`請求關閉偵錯時，請省略 `exceptionLevel` 欄位。

## 開啟和關閉偵錯的範例閘道回應
<a name="gateway-building-debug-ex"></a>

例如，假設使用者沒有叫用閘道目標 Lambda 函數的許可。呼叫此函數的請求會根據偵錯是開啟還是關閉，傳回不同的訊息：
+  **除錯 **- 詳細的錯誤訊息會在內容的 `text` 欄位中傳回，也會在回應的 `_meta`欄位中傳回，如下列範例所示：

  ```
  {
    "jsonrpc": "2.0",
    "id": 24,
    "result": {
      "content": [
        {
          "type": "text",
          "text": "Access denied while invoking Lambda function arn:aws:lambda:us-west-2:123456789012:function:TestGatewayLambda. Check the permissions on the Lambda function and Gateway execution role, and retry the request."
        }
      ],
      "_meta": {
        "debug": {
          "type": "text",
          "text": "Access denied while invoking Lambda function arn:aws:lambda:us-west-2:123456789012:function:TestGatewayLambda. Check the permissions on the Lambda function and Gateway execution role, and retry the request."
        }
      },
      "isError": true
    }
  }
  ```
+  **除錯** – 回應中內容的 `text` 欄位會傳回一般錯誤訊息，如下列範例所示：

  ```
  {
    "jsonrpc": "2.0",
    "id": 24,
    "result": {
      "content": [
        {
          "type": "text",
          "text": "An internal error occurred. Please retry later."
        }
      ],
      "isError": true
    }
  }
  ```