* Formats an error message based on the error type and context
(error: unknown, errorType: string, _isStreamContext: boolean)
| 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 |
no test coverage detected