feat: initial Netts energy orchestrator

This commit is contained in:
你的用户名
2025-11-03 19:26:48 +08:00
commit 891c32e288
25 changed files with 2210 additions and 0 deletions

36
pkg/errors/api_error.go Normal file
View File

@@ -0,0 +1,36 @@
package errors
import "fmt"
// APIError represents a structured error from an upstream API.
type APIError struct {
Code int
Message string
HTTPStatus int
}
func (e *APIError) Error() string {
if e == nil {
return "<nil>"
}
if e.HTTPStatus > 0 {
return fmt.Sprintf("api error: status=%d code=%d message=%s", e.HTTPStatus, e.Code, e.Message)
}
return fmt.Sprintf("api error: code=%d message=%s", e.Code, e.Message)
}
// Temporary returns true when the error is potentially recoverable.
func (e *APIError) Temporary() bool {
if e == nil {
return false
}
if e.HTTPStatus >= 500 {
return true
}
switch e.Code {
case 429:
return true
default:
return false
}
}