chore: refactor permanent errors (#25341)

This commit is contained in:
andig 2025-11-16 10:05:50 +01:00 • committed by GitHub
parent c90258b6e4
commit b47b2e12ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,10 @@
package api
import "errors"
import (
"errors"
"github.com/cenkalti/backoff/v4"
)
// ErrNotAvailable indicates that a feature is not available
var ErrNotAvailable = errors.New("not available")
@ -12,26 +16,19 @@ var ErrMustRetry = errors.New("must retry")
var ErrSponsorRequired = errors.New("sponsorship required, see https://docs.evcc.io/docs/sponsorship")
// ErrMissingCredentials indicates that user/password are missing
var ErrMissingCredentials = errors.New("missing user/password credentials")
var ErrMissingCredentials = backoff.Permanent(errors.New("missing user/password credentials"))
// ErrLoginRequired indicates that retrieving tokens credentials waits for login
var ErrLoginRequired = errors.New("login required")
var ErrLoginRequired = backoff.Permanent(errors.New("login required"))
// ErrMissingToken indicates that access/refresh tokens are missing
var ErrMissingToken = errors.New("missing token credentials")
var ErrMissingToken = backoff.Permanent(errors.New("missing token credentials"))
// ErrOutdated indicates that result is outdated
var ErrOutdated = errors.New("outdated")
// ErrTimeout is the error returned when a timeout happened.
// Modeled after context.DeadlineError
var ErrTimeout error = errTimeoutError{}
type errTimeoutError struct{}
func (errTimeoutError) Error() string { return "timeout" }
func (errTimeoutError) Timeout() bool { return true }
func (errTimeoutError) Temporary() bool { return true }
// ErrTimeout is the error returned when a timeout happened
var ErrTimeout error = errors.New("timeout")
// ErrAsleep indicates that vehicle is asleep. Caller may chose to wake up the vehicle and retry.
var ErrAsleep error = errAsleep{}