From be71e5a321ab4044abffd4dd79128d003f583358 Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Thu, 2 Apr 2026 22:09:37 +0200 Subject: [PATCH] error handler hardened --- src/Agent/AutopilotMonitor.Agent/buildcounter.txt | 2 +- .../AutopilotMonitor.Functions/Helpers/ResponseHelper.cs | 8 +++++--- .../autopilot-monitor-mcp/src/tools/error-handler.ts | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt index 34eafc3d..8832c4db 100644 --- a/src/Agent/AutopilotMonitor.Agent/buildcounter.txt +++ b/src/Agent/AutopilotMonitor.Agent/buildcounter.txt @@ -1 +1 @@ -797 +798 diff --git a/src/Backend/AutopilotMonitor.Functions/Helpers/ResponseHelper.cs b/src/Backend/AutopilotMonitor.Functions/Helpers/ResponseHelper.cs index 50dfa5b3..4a7b6c35 100644 --- a/src/Backend/AutopilotMonitor.Functions/Helpers/ResponseHelper.cs +++ b/src/Backend/AutopilotMonitor.Functions/Helpers/ResponseHelper.cs @@ -131,12 +131,14 @@ public static class ResponseHelper { return ex switch { + RequestFailedException rfe when rfe.ErrorCode != null => + $"{operation}: {rfe.ErrorCode} — {rfe.Message}", RequestFailedException rfe => - $"{operation}: {rfe.ErrorCode ?? $"Azure error (HTTP {rfe.Status})"} — {rfe.Message}", + $"{operation}: Azure error (HTTP {rfe.Status}). Use correlationId to investigate in backend logs.", ArgumentException ae => $"{operation}: Invalid argument — {ae.Message}", - InvalidOperationException ioe => - $"{operation}: {ioe.Message}", + InvalidOperationException => + $"{operation}: Invalid operation. Use correlationId to investigate in backend logs.", TimeoutException => $"{operation}: The operation timed out", TaskCanceledException => diff --git a/src/McpServer/autopilot-monitor-mcp/src/tools/error-handler.ts b/src/McpServer/autopilot-monitor-mcp/src/tools/error-handler.ts index 1badc79b..0440bee7 100644 --- a/src/McpServer/autopilot-monitor-mcp/src/tools/error-handler.ts +++ b/src/McpServer/autopilot-monitor-mcp/src/tools/error-handler.ts @@ -40,7 +40,9 @@ export function toolError( } else if (error.status === 429) { parts.push(`**Rate limited in ${toolName}**: Too many requests. Wait a moment and retry.`); } else { - parts.push(`**Error in ${toolName}** (HTTP ${error.status}): ${error.body || 'No response body'}`); + const body = error.body || 'No response body'; + const truncated = body.length > 500 ? body.slice(0, 500) + '…' : body; + parts.push(`**Error in ${toolName}** (HTTP ${error.status}): ${truncated}`); } } else { const message = error instanceof Error ? error.message : String(error);