Skip to content

Commit 82a9025

Browse files
committed
feat: add verbose error display with error codes and debug information
1 parent 8f840af commit 82a9025

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

src/api/providers/__tests__/bedrock-error-handling.spec.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,13 @@ describe("AwsBedrockHandler Error Handling", () => {
4242
name?: string
4343
status?: number
4444
__type?: string
45-
$metadata?: { httpStatusCode?: number }
45+
$metadata?: {
46+
httpStatusCode?: number
47+
requestId?: string
48+
extendedRequestId?: string
49+
cfId?: string
50+
[key: string]: any // Allow additional properties
51+
}
4652
}): Error => {
4753
const error = new Error(options.message || "Test error") as any
4854
if (options.name) error.name = options.name
@@ -128,7 +134,7 @@ describe("AwsBedrockHandler Error Handling", () => {
128134
const result = await handler.completePrompt("test")
129135
expect(result).toContain("throttled or rate limited")
130136
} catch (error) {
131-
expect(error.message).toContain("throttled or rate limited")
137+
expect(error.message).toMatch(/throttled or rate limited/)
132138
}
133139
})
134140

@@ -156,6 +162,37 @@ describe("AwsBedrockHandler Error Handling", () => {
156162
}
157163
}
158164
})
165+
166+
it("should display verbose error information including codes and metadata", async () => {
167+
const verboseError = createMockError({
168+
message: "Bedrock is unable to process your request",
169+
name: "ThrottlingException",
170+
status: 429,
171+
$metadata: {
172+
httpStatusCode: 429,
173+
requestId: "12345-abcde-67890",
174+
extendedRequestId: "extended-12345",
175+
cfId: "cf-12345",
176+
},
177+
})
178+
179+
mockSend.mockRejectedValueOnce(verboseError)
180+
181+
try {
182+
await handler.completePrompt("test")
183+
throw new Error("Expected error to be thrown")
184+
} catch (error) {
185+
// Should contain error codes
186+
expect(error.message).toMatch(/\[.*HTTP 429.*AWS ThrottlingException.*\]/)
187+
// Should contain the main error message
188+
expect(error.message).toContain("throttled or rate limited")
189+
// Should contain debug information
190+
expect(error.message).toContain("Debug Info:")
191+
expect(error.message).toContain("Request ID: 12345-abcde-67890")
192+
expect(error.message).toContain("Extended Request ID: extended-12345")
193+
expect(error.message).toContain("CloudFront ID: cf-12345")
194+
}
195+
})
159196
})
160197

161198
describe("Service Quota Exceeded Detection", () => {

src/api/providers/bedrock.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,48 @@ Please check:
12311231
templateVars.modelId = modelConfig.id
12321232
templateVars.contextWindow = String(modelConfig.info.contextWindow || "unknown")
12331233

1234+
// Extract error codes and identifiers for verbose display
1235+
const errorCodes: string[] = []
1236+
const errorMeta: string[] = []
1237+
1238+
// HTTP Status Code
1239+
if ((error as any).status) {
1240+
errorCodes.push(`HTTP ${(error as any).status}`)
1241+
}
1242+
if ((error as any).$metadata?.httpStatusCode) {
1243+
errorCodes.push(`HTTP ${(error as any).$metadata.httpStatusCode}`)
1244+
}
1245+
1246+
// AWS Error Codes
1247+
if (error.name && error.name !== "Error") {
1248+
errorCodes.push(`AWS ${error.name}`)
1249+
}
1250+
if ((error as any).__type) {
1251+
errorCodes.push(`Type ${(error as any).__type}`)
1252+
}
1253+
1254+
// Request ID for debugging
1255+
if ((error as any).$metadata?.requestId) {
1256+
errorMeta.push(`Request ID: ${(error as any).$metadata.requestId}`)
1257+
}
1258+
if ((error as any).requestId) {
1259+
errorMeta.push(`Request ID: ${(error as any).requestId}`)
1260+
}
1261+
1262+
// Extended Request ID (S3/CloudFront style)
1263+
if ((error as any).$metadata?.extendedRequestId) {
1264+
errorMeta.push(`Extended Request ID: ${(error as any).$metadata.extendedRequestId}`)
1265+
}
1266+
1267+
// CF Request ID (CloudFront)
1268+
if ((error as any).$metadata?.cfId) {
1269+
errorMeta.push(`CloudFront ID: ${(error as any).$metadata.cfId}`)
1270+
}
1271+
1272+
// Build error code display
1273+
templateVars.errorCodes = errorCodes.length > 0 ? `[${errorCodes.join(", ")}]` : ""
1274+
templateVars.errorMetadata = errorMeta.length > 0 ? `\n\nDebug Info:\n${errorMeta.join("\n")}` : ""
1275+
12341276
// Format error details
12351277
const errorDetails: Record<string, any> = {}
12361278
Object.getOwnPropertyNames(error).forEach((prop) => {
@@ -1275,6 +1317,16 @@ Please check:
12751317
template = template.replace(new RegExp(`{${key}}`, "g"), value || "")
12761318
}
12771319

1320+
// Add error codes at the beginning if available
1321+
if (templateVars.errorCodes) {
1322+
template = `${templateVars.errorCodes} ${template}`
1323+
}
1324+
1325+
// Add metadata at the end if available
1326+
if (templateVars.errorMetadata) {
1327+
template = `${template}${templateVars.errorMetadata}`
1328+
}
1329+
12781330
return template
12791331
}
12801332

0 commit comments

Comments
 (0)