error handler hardened

This commit is contained in:
Oliver Kieselbach
2026-04-02 22:09:37 +02:00
parent d824dd64fd
commit be71e5a321
3 changed files with 9 additions and 5 deletions
@@ -1 +1 @@
797
798
@@ -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 =>
@@ -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);