Skip to content

Commit 2471af8

Browse files
feat(cmd): add API validation tool for quick configuration testing
1 parent 1ddb40a commit 2471af8

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

cmd/validate-api/main.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353
if len(key) > 7 {
5454
displayKey = key[:7]
5555
}
56-
fmt.Printf("🔑 API Key: %s...\n", displayKey)
56+
fmt.Printf("API Key: %s...\n", displayKey)
5757
fmt.Println()
5858
}
5959

@@ -63,9 +63,9 @@ func main() {
6363
os.Exit(1)
6464
}
6565

66-
fmt.Println("✅ API connection successful")
66+
fmt.Println("Your OpenAI configuration is working correctly!")
6767
if *verbose {
68-
fmt.Println("🎉 Your OpenAI configuration is working correctly!")
68+
fmt.Println("🎉")
6969
}
7070
}
7171

@@ -76,45 +76,45 @@ func validateAPI(ctx context.Context, client openai.Client) error {
7676
}
7777

7878
func handleError(err error) {
79-
fmt.Fprintf(os.Stderr, "API Error: %v\n\n", err)
79+
fmt.Fprintf(os.Stderr, "API Error: %v\n\n", err)
8080

8181
if apiErr, ok := err.(*apierror.Error); ok {
8282
switch apiErr.StatusCode {
8383
case 401:
84-
fmt.Fprintln(os.Stderr, "🔐 Authentication issue:")
84+
fmt.Fprintln(os.Stderr, " Authentication issue:")
8585
fmt.Fprintln(os.Stderr, " • Verify your API key is correct")
8686
fmt.Fprintln(os.Stderr, " • Check at https://platform.openai.com/api-keys")
8787
fmt.Fprintln(os.Stderr, " • Ensure your account has available credits")
8888
case 403:
89-
fmt.Fprintln(os.Stderr, "🚫 Access denied:")
89+
fmt.Fprintln(os.Stderr, " Access denied:")
9090
fmt.Fprintln(os.Stderr, " • Check your API key permissions")
9191
fmt.Fprintln(os.Stderr, " • Verify your subscription plan")
9292
case 429:
93-
fmt.Fprintln(os.Stderr, "⏱️ Rate limit exceeded:")
93+
fmt.Fprintln(os.Stderr, " Rate limit exceeded:")
9494
fmt.Fprintln(os.Stderr, " • Wait a few minutes")
9595
fmt.Fprintln(os.Stderr, " • Check your quota at https://platform.openai.com/usage")
9696
case 500, 502, 503, 504:
97-
fmt.Fprintln(os.Stderr, "🌐 OpenAI server issue:")
97+
fmt.Fprintln(os.Stderr, " OpenAI server issue:")
9898
fmt.Fprintln(os.Stderr, " • OpenAI service is temporarily unavailable")
9999
fmt.Fprintln(os.Stderr, " • Try again in a few minutes")
100100
default:
101-
fmt.Fprintf(os.Stderr, "�� Error code: %d\n", apiErr.StatusCode)
102-
fmt.Fprintf(os.Stderr, "📝 Message: %s\n", apiErr.Message)
101+
fmt.Fprintf(os.Stderr, " Error code: %d\n", apiErr.StatusCode)
102+
fmt.Fprintf(os.Stderr, " Message: %s\n", apiErr.Message)
103103
}
104104
} else {
105105
errStr := err.Error()
106-
if strings.Contains(errStr, "connection refused") {
107-
fmt.Fprintln(os.Stderr, "🌐 Connection issue:")
106+
if strings.Contains(errStr, "Connection refused") {
107+
fmt.Fprintln(os.Stderr, " Connection issue:")
108108
fmt.Fprintln(os.Stderr, " • Check your internet connection")
109109
fmt.Fprintln(os.Stderr, " • Verify your proxy/firewall settings")
110110
} else if strings.Contains(errStr, "timeout") {
111-
fmt.Fprintln(os.Stderr, " Connection timeout:")
111+
fmt.Fprintln(os.Stderr, " Connection timeout:")
112112
fmt.Fprintln(os.Stderr, " • Check your internet connection")
113113
fmt.Fprintln(os.Stderr, " • Increase timeout with --timeout 30s")
114114
} else {
115-
fmt.Fprintf(os.Stderr, "Unknown error: %s\n", errStr)
115+
fmt.Fprintf(os.Stderr, "Unknown error: %s\n", errStr)
116116
}
117117
}
118118

119-
fmt.Fprintln(os.Stderr, "\n💡 For more help: https://platform.openai.com/docs/guides/error-codes")
119+
fmt.Fprintln(os.Stderr, "\n For more help: https://platform.openai.com/docs/guides/error-codes")
120120
}

0 commit comments

Comments
 (0)