feat: initial Netts energy orchestrator
This commit is contained in:
36
pkg/errors/api_error.go
Normal file
36
pkg/errors/api_error.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user