retryMessage produces a clean factual description suitable for display alongside the retry countdown UI. It omits HTTP status codes (surfaced separately in the payload) and remediation guidance (not actionable while auto-retrying).
(classified ClassifiedError)
| 78 | // codes (surfaced separately in the payload) and remediation |
| 79 | // guidance (not actionable while auto-retrying). |
| 80 | func retryMessage(classified ClassifiedError) string { |
| 81 | if classified.Retryable && classified.Message != "" { |
| 82 | return classified.Message |
| 83 | } |
| 84 | |
| 85 | subject := providerSubject(classified.Provider) |
| 86 | switch classified.Kind { |
| 87 | case codersdk.ChatErrorKindOverloaded: |
| 88 | return stringutil.Capitalize(fmt.Sprintf("%s is temporarily overloaded.", subject)) |
| 89 | case codersdk.ChatErrorKindRateLimit: |
| 90 | return stringutil.Capitalize(fmt.Sprintf("%s is rate limiting requests.", subject)) |
| 91 | case codersdk.ChatErrorKindTimeout: |
| 92 | return stringutil.Capitalize(fmt.Sprintf("%s is temporarily unavailable.", subject)) |
| 93 | case codersdk.ChatErrorKindStartupTimeout: |
| 94 | return stringutil.Capitalize(fmt.Sprintf( |
| 95 | "%s did not start responding in time.", subject, |
| 96 | )) |
| 97 | case codersdk.ChatErrorKindAuth: |
| 98 | return fmt.Sprintf( |
| 99 | "Authentication with %s failed.", subject, |
| 100 | ) |
| 101 | case codersdk.ChatErrorKindConfig: |
| 102 | return stringutil.Capitalize(fmt.Sprintf( |
| 103 | "%s rejected the model configuration.", subject, |
| 104 | )) |
| 105 | case codersdk.ChatErrorKindProviderDisabled: |
| 106 | displayName := providerDisplayName(classified.Provider) |
| 107 | return fmt.Sprintf( |
| 108 | "The %s provider has been disabled by an administrator.", |
| 109 | displayName, |
| 110 | ) |
| 111 | case codersdk.ChatErrorKindMissingKey: |
| 112 | return "The API key for this conversation is no longer available." |
| 113 | default: |
| 114 | return stringutil.Capitalize(fmt.Sprintf( |
| 115 | "%s returned an unexpected error.", subject, |
| 116 | )) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | func providerSubject(provider string) string { |
| 121 | if displayName := providerDisplayName(provider); displayName != "AI" && displayName != "" { |
no test coverage detected