fix(providers): surface friendly auth error messages (#3198)
This commit is contained in:
8 files changed
+482
-15
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/providers"
|
||||
)
|
||||
|
||||
func formatProcessingError(err error) string {
|
||||
if err == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if kind, ok := providers.ClassifyAuthError(err); ok {
|
||||
return fmt.Sprintf(
|
||||
"Error processing message: %s\n\nOriginal error:\n%s",
|
||||
authErrorFriendlyMessage(kind),
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Error processing message: %v", err)
|
||||
}
|
||||
|
||||
func authErrorFriendlyMessage(kind providers.AuthErrorKind) string {
|
||||
switch kind {
|
||||
case providers.AuthErrorInvalidAPIKey:
|
||||
return "Authentication failed: the API key appears to be invalid. Check the API key configured for this model or provider."
|
||||
case providers.AuthErrorMissingAPIKey:
|
||||
return "Authentication failed: no API key is configured for this model or provider. Add an API key in the model settings or config."
|
||||
case providers.AuthErrorExpiredToken:
|
||||
return "Authentication failed: the saved login or token appears to be expired. Re-authenticate the provider."
|
||||
default:
|
||||
return "Authentication failed: check the API key, token, OAuth login, or provider permissions for this model."
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user