Add projects
This commit is contained in:
parent
2d3a9ad623
commit
8b607dd700
1802 changed files with 503346 additions and 2 deletions
71
backend/sdk/cliproxy/auth/errors.go
Normal file
71
backend/sdk/cliproxy/auth/errors.go
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package auth
|
||||
|
||||
// ErrorCodeRequestScoped identifies failures tied to the current request rather
|
||||
// than the selected credential.
|
||||
const ErrorCodeRequestScoped = "request_scoped"
|
||||
|
||||
const requestScopedErrorCode = ErrorCodeRequestScoped
|
||||
|
||||
// ErrorCodeConnectionLifecycle marks transport/session lifecycle failures that
|
||||
// must skip credential cooldown without being treated as request-scoped faults.
|
||||
const ErrorCodeConnectionLifecycle = "connection_lifecycle"
|
||||
|
||||
const connectionLifecycleErrorCode = ErrorCodeConnectionLifecycle
|
||||
|
||||
// ErrorCodeForceCooldown marks failures that must enforce credential cooldown.
|
||||
const ErrorCodeForceCooldown = "force_cooldown"
|
||||
|
||||
// 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 == ErrorCodeRequestScoped
|
||||
}
|
||||
|
||||
// MarkRequestScoped marks the error as request-scoped in place and returns it.
|
||||
func (e *Error) MarkRequestScoped() *Error {
|
||||
if e != nil {
|
||||
e.Code = ErrorCodeRequestScoped
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
// NewRequestScopedError creates an Error explicitly flagged as request-scoped so
|
||||
// that credential cooldown is skipped.
|
||||
func NewRequestScopedError(message string, httpStatus int) *Error {
|
||||
return &Error{
|
||||
Code: ErrorCodeRequestScoped,
|
||||
Message: message,
|
||||
HTTPStatus: httpStatus,
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue