60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package identity
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
// ErrRateLimited reports a request refused by the per-address limit.
|
|
// errors.As with *RateLimitedError yields the wait.
|
|
ErrRateLimited = errors.New("rate limit exceeded")
|
|
|
|
// ErrIdempotencyKeyReused reports a key that was first used with another
|
|
// request body for the same address.
|
|
ErrIdempotencyKeyReused = errors.New("idempotency key reused with a different request")
|
|
|
|
// ErrInvalidField reports a request value outside its rules.
|
|
// errors.As with *InvalidFieldError yields the JSON Pointer of the field.
|
|
ErrInvalidField = errors.New("invalid request field")
|
|
|
|
// ErrVerificationTokenInvalid reports an unknown, used, replaced, or
|
|
// otherwise unusable email verification token.
|
|
ErrVerificationTokenInvalid = errors.New("verification token invalid")
|
|
|
|
// ErrVerificationTokenExpired reports an email verification token past its
|
|
// expiry time.
|
|
ErrVerificationTokenExpired = errors.New("verification token expired")
|
|
)
|
|
|
|
// RateLimitedError carries how long the caller waits before a repeat can be
|
|
// accepted. It matches ErrRateLimited.
|
|
type RateLimitedError struct {
|
|
RetryAfter time.Duration
|
|
}
|
|
|
|
func (err *RateLimitedError) Error() string {
|
|
return fmt.Sprintf("rate limit exceeded, retry after %s", err.RetryAfter)
|
|
}
|
|
|
|
func (err *RateLimitedError) Unwrap() error { return ErrRateLimited }
|
|
|
|
// InvalidFieldError names the body field that failed and why, without the
|
|
// value. Pointer is the JSON Pointer of the field in the request body. It
|
|
// matches ErrInvalidField and also the domain error it wraps.
|
|
type InvalidFieldError struct {
|
|
Pointer string
|
|
Err error
|
|
}
|
|
|
|
func (err *InvalidFieldError) Error() string {
|
|
return fmt.Sprintf("invalid request field %s: %v", err.Pointer, err.Err)
|
|
}
|
|
|
|
func (err *InvalidFieldError) Unwrap() []error { return []error{ErrInvalidField, err.Err} }
|
|
|
|
func invalidField(pointer string, cause error) error {
|
|
return &InvalidFieldError{Pointer: pointer, Err: cause}
|
|
}
|