shad-go/retryupdate/kvapi/errors.go

51 lines
803 B
Go
Raw Normal View History

2020-03-07 19:14:49 +00:00
// +build !change
package kvapi
import (
2020-03-11 13:17:13 +00:00
"errors"
2020-03-07 19:14:49 +00:00
"fmt"
"github.com/gofrs/uuid"
)
var (
2020-03-07 19:15:30 +00:00
_ error = (*APIError)(nil)
2020-03-07 19:14:49 +00:00
_ error = (*ConflictError)(nil)
_ error = (*AuthError)(nil)
)
2020-03-11 13:17:13 +00:00
var ErrKeyNotFound = errors.New("key not found")
2020-03-07 19:14:49 +00:00
type (
2020-03-07 19:15:30 +00:00
APIError struct {
2020-03-07 19:14:49 +00:00
Method string
Err error
}
ConflictError struct {
ProvidedVersion, ExpectedVersion uuid.UUID
}
AuthError struct {
Msg string
}
)
2020-03-07 19:15:30 +00:00
func (a *APIError) Error() string {
2020-03-07 19:14:49 +00:00
return fmt.Sprintf("api: %q error: %v", a.Method, a.Err)
}
2020-03-07 19:15:30 +00:00
func (a *APIError) Unwrap() error {
2020-03-07 19:14:49 +00:00
return a.Err
}
func (a *ConflictError) Error() string {
return fmt.Sprintf("api: conflict: expected_version=%d, provided_version=%d", a.ExpectedVersion, a.ProvidedVersion)
}
func (a *AuthError) Error() string {
return fmt.Sprintf("api: auth: %s", a.Msg)
}