mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-09-08 17:11:19 +08:00
- Added a dedicated `connection_lifecycle` error code and lifecycle detection for context cancellation, EOF variants, and websocket close conditions. - Introduced shared gating (`shouldSkipCredentialCooldown`) so transport/session lifecycle failures do not mark auth/model as unavailable or set retry cooldown. - Kept request-scoped/invalid failures as high-priority and preserved status-bearing HTTP errors behavior so auth cooldown still applies when appropriate. Closes: #4819 #4787
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package auth
|
|
|
|
const requestScopedErrorCode = "request_scoped"
|
|
|
|
// connectionLifecycleErrorCode marks transport/session lifecycle failures that
|
|
// must skip credential cooldown without being treated as request-scoped faults.
|
|
const connectionLifecycleErrorCode = "connection_lifecycle"
|
|
|
|
// Error describes an authentication related failure in a provider agnostic format.
|
|
type Error struct {
|
|
// Code is a short machine readable identifier.
|
|
Code string `json:"code,omitempty"`
|
|
// Message is a human readable description of the failure.
|
|
Message string `json:"message"`
|
|
// Retryable indicates whether a retry might fix the issue automatically.
|
|
Retryable bool `json:"retryable"`
|
|
// HTTPStatus optionally records an HTTP-like status code for the error.
|
|
HTTPStatus int `json:"http_status,omitempty"`
|
|
}
|
|
|
|
// Error implements the error interface.
|
|
func (e *Error) Error() string {
|
|
if e == nil {
|
|
return ""
|
|
}
|
|
if e.Code == "" {
|
|
return e.Message
|
|
}
|
|
return e.Code + ": " + e.Message
|
|
}
|
|
|
|
// StatusCode implements optional status accessor for manager decision making.
|
|
func (e *Error) StatusCode() int {
|
|
if e == nil {
|
|
return 0
|
|
}
|
|
return e.HTTPStatus
|
|
}
|
|
|
|
// IsRequestScoped reports whether the failure is tied to the current request
|
|
// rather than the selected credential.
|
|
func (e *Error) IsRequestScoped() bool {
|
|
return e != nil && e.Code == requestScopedErrorCode
|
|
}
|