fix(providers): surface friendly auth error messages (#3198)
This commit is contained in:
8 files changed
+482
-15
No files matched your search
@@ -8,6 +8,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/sipeed/picoclaw/pkg/providers/common"
|
||||
)
|
||||
|
||||
// Common patterns in Go HTTP error messages
|
||||
@@ -88,6 +90,8 @@ var (
|
||||
}
|
||||
|
||||
authPatterns = []errorPattern{
|
||||
rxp(`\b(?:invalid|incorrect|malformed|wrong)[-_\s]+(?:api[-_\s]*)?key\b`),
|
||||
rxp(`\b(?:api[-_\s]*)?key[-_\s]+(?:is[-_\s]+)?(?:invalid|incorrect|malformed|wrong)\b`),
|
||||
rxp(`invalid[_ ]?api[_ ]?key`),
|
||||
substr("incorrect api key"),
|
||||
substr("invalid token"),
|
||||
@@ -188,6 +192,18 @@ func ClassifyError(err error, provider, model string) *FailoverError {
|
||||
}
|
||||
|
||||
// Try HTTP status code extraction first.
|
||||
var httpErr *common.HTTPError
|
||||
if errors.As(err, &httpErr) && httpErr != nil {
|
||||
if reason := classifyByStatus(httpErr.StatusCode); reason != "" {
|
||||
return &FailoverError{
|
||||
Reason: reason,
|
||||
Provider: provider,
|
||||
Model: model,
|
||||
Status: httpErr.StatusCode,
|
||||
Wrapped: err,
|
||||
}
|
||||
}
|
||||
}
|
||||
if status := extractHTTPStatus(msg); status > 0 {
|
||||
if reason := classifyByStatus(status); reason != "" {
|
||||
return &FailoverError{
|
||||
|
||||
Reference in new issue
Block a user