2023-12-08 16:30:55 +02:00
|
|
|
package zerrors
|
2023-02-15 02:52:11 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_ ResourceExhausted = (*ResourceExhaustedError)(nil)
|
|
|
|
_ Error = (*ResourceExhaustedError)(nil)
|
|
|
|
)
|
|
|
|
|
|
|
|
type ResourceExhausted interface {
|
|
|
|
error
|
|
|
|
IsResourceExhausted()
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceExhaustedError struct {
|
2023-12-08 16:30:55 +02:00
|
|
|
*ZitadelError
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func ThrowResourceExhausted(parent error, id, message string) error {
|
2023-12-08 16:30:55 +02:00
|
|
|
return &ResourceExhaustedError{CreateZitadelError(parent, id, message)}
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func ThrowResourceExhaustedf(parent error, id, format string, a ...interface{}) error {
|
|
|
|
return ThrowResourceExhausted(parent, id, fmt.Sprintf(format, a...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ResourceExhaustedError) IsResourceExhausted() {}
|
|
|
|
|
|
|
|
func IsResourceExhausted(err error) bool {
|
|
|
|
//nolint:errorlint
|
|
|
|
_, ok := err.(ResourceExhausted)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ResourceExhaustedError) Is(target error) bool {
|
|
|
|
//nolint:errorlint
|
|
|
|
t, ok := target.(*ResourceExhaustedError)
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
2023-12-08 16:30:55 +02:00
|
|
|
return err.ZitadelError.Is(t.ZitadelError)
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (err *ResourceExhaustedError) Unwrap() error {
|
2023-12-08 16:30:55 +02:00
|
|
|
return err.ZitadelError
|
2023-02-15 02:52:11 +01:00
|
|
|
}
|