Files
ProxyPilot/internal/errors/app_error.go
RCD 0af0ad14e5 Merge upstream CLIProxyAPI v6.8.28–v6.8.32
Upstream changes:
- Codex responses compaction payload compatibility
- Codex usage_limit_reached retry-after, deterministic parsing
- Codex refresh_token_reused non-retryable fix
- Qwen rate limiting and quota error handling
- Context management compatibility simplification
- Antigravity tool_result image fix, model list backfill, deep copy cache
- Auth auto-refresh interval/concurrency limiting
- Auth hook OnResult refactor (replaces MarkResult)
- Gemini-3.1-flash-image support
- Registry cleanup of outdated model definitions

Fork resolution:
- Accept upstream's consolidated conductor.go (auto-refresh, round-tripper)
- Delete stale conductor_oauth.go, conductor_token.go (upstream reversed split)
- Delete stale provider_rotation_test.go (references removed method)
2026-02-27 20:58:16 +07:00

49 lines
1.1 KiB
Go

package errors
import (
"encoding/json"
"fmt"
)
// AppError represents a structured application error.
type AppError struct {
// HTTPStatusCode is the HTTP status code to return.
HTTPStatusCode int `json:"-"`
// Code is an internal error code string.
Code string `json:"code"`
// Message is the user-facing error message.
Message string `json:"message"`
// Details provides additional error context (optional).
Details map[string]interface{} `json:"details,omitempty"`
// Err is the underlying error (not marshaled to JSON).
Err error `json:"-"`
}
func (e *AppError) Error() string {
if e.Err != nil {
return fmt.Sprintf("%s: %v", e.Message, e.Err)
}
return e.Message
}
// Unwrap returns the underlying error.
func (e *AppError) Unwrap() error {
return e.Err
}
// ToJSON returns the JSON byte representation of the error.
func (e *AppError) ToJSON() []byte {
b, _ := json.Marshal(e)
return b
}
// New creates a new AppError.
func New(statusCode int, code, message string, err error) *AppError {
return &AppError{
HTTPStatusCode: statusCode,
Code: code,
Message: message,
Err: err,
}
}