MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / formatErrorForDisplay

Function formatErrorForDisplay

cli/src/utils/error-messages.ts:8–44  ·  view source on GitHub ↗
(error: unknown, fallbackTitle: string)

Source from the content-addressed store, hash-verified

6 * The goal is to provide clear, consistent messaging across the CLI.
7 */
8export function formatErrorForDisplay(error: unknown, fallbackTitle: string): string {
9 const statusCode = getErrorStatusCode(error)
10
11 // Authentication-specific messaging based on statusCode
12 if (statusCode === 401) {
13 return `${fallbackTitle}: Authentication failed. Please check your API key.`
14 }
15 if (statusCode === 403) {
16 return `${fallbackTitle}: Access forbidden. You do not have permission to access this resource.`
17 }
18
19 // Network/server error messaging based on statusCode
20 if (statusCode !== undefined) {
21 if (statusCode === 408) {
22 return `${fallbackTitle}: Request timed out. Please check your internet connection.`
23 }
24 if (statusCode === 503) {
25 return `${fallbackTitle}: Service unavailable. The server may be down.`
26 }
27 if (statusCode >= 500) {
28 return `${fallbackTitle}: Server error. Please try again later.`
29 }
30 if (statusCode === 429) {
31 return `${fallbackTitle}: Rate limited. Please try again later.`
32 }
33 }
34
35 // Generic Error instance
36 if (error instanceof Error) {
37 const message = error.message || 'An unexpected error occurred.'
38 return `${fallbackTitle}: ${message}`
39 }
40
41 // Try sanitizeErrorMessage for other cases
42 const safeMessage = sanitizeErrorMessage(error)
43 return `${fallbackTitle}: ${safeMessage}`
44}
45
46/**
47 * Formats a retry banner message for offline / retry scenarios.

Callers 1

formatRetryBannerMessageFunction · 0.85

Calls 2

getErrorStatusCodeFunction · 0.90
sanitizeErrorMessageFunction · 0.90

Tested by

no test coverage detected