MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / formatErrorMessage

Method formatErrorMessage

src/api/providers/bedrock.ts:1582–1611  ·  view source on GitHub ↗

* Formats an error message based on the error type and context

(error: unknown, errorType: string, _isStreamContext: boolean)

Source from the content-addressed store, hash-verified

1580 * Formats an error message based on the error type and context
1581 */
1582 private formatErrorMessage(error: unknown, errorType: string, _isStreamContext: boolean): string {
1583 const definition = AwsBedrockHandler.ERROR_TYPES[errorType] || AwsBedrockHandler.ERROR_TYPES.GENERIC
1584 let template = definition.messageTemplate
1585
1586 // Prepare template variables
1587 const templateVars: Record<string, string> = {}
1588
1589 if (error instanceof Error) {
1590 templateVars.errorMessage = error.message
1591 templateVars.errorName = error.name
1592
1593 const modelConfig = this.getModel()
1594 templateVars.modelId = modelConfig.id
1595 templateVars.contextWindow = String(modelConfig.info.contextWindow || "unknown")
1596 }
1597
1598 // Add context-specific template variables
1599 const region =
1600 typeof this?.client?.config?.region === "function"
1601 ? this?.client?.config?.region()
1602 : this?.client?.config?.region
1603 templateVars.regionInfo = `(${region})`
1604
1605 // Replace template variables
1606 for (const [key, value] of Object.entries(templateVars)) {
1607 template = template.replace(new RegExp(`{${key}}`, "g"), value || "")
1608 }
1609
1610 return template
1611 }
1612
1613 /**
1614 * Handles Bedrock API errors and generates appropriate error messages

Callers 2

createMessageMethod · 0.95
handleBedrockErrorMethod · 0.95

Calls 4

getModelMethod · 0.95
entriesMethod · 0.80
replaceMethod · 0.65
StringInterface · 0.50

Tested by

no test coverage detected