mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-02 17:08:51 +00:00
feat(domain): introduce error slugs (#12030)
# Which Problems Are Solved As part of https://github.com/zitadel/zitadel/issues/11917 we want to introduce error slugs so (API) clients can rely on stable, machine-readable errors and act accordingly. # How the Problems Are Solved - Added a `NewSlug` helper function in the domain package. - Added `ErrorDetails` to the `ZitadelError` - Added an `zitadel.error.v2.ErrorDetail` proto message - Updated the connectRPC error interceptor to map new slug based errors to the new `ErrorDetail` - Defined some common slugs and error functions like internal errors - Defined (session) specific slugs used in the `DeleteSession` and `CheckUser` functions and replaced old implementations - Updated integration tests to check specific errors if the relation database feature is enabled - Updated doc and guideline to reflect the latest changes and decisions - Updated DeleteSession endpoint API to list possible slugs # Additional Changes None # Additional Context - closes #11957 --------- Co-authored-by: Wim Van Laer <[email protected]>
This commit is contained in:
co-authored by
Wim Van Laer
parent
5c9361f6c7
commit
a2bf528ca0
@@ -6,6 +6,7 @@ import (
|
||||
"golang.org/x/text/language"
|
||||
|
||||
"github.com/zitadel/zitadel/internal/crypto"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
@@ -252,3 +253,26 @@ type HumanRecoveryCodes struct {
|
||||
// It is reset to 0 on successful verification
|
||||
FailedAttempts uint8 `json:"failedAttempts,omitempty" db:"-"`
|
||||
}
|
||||
|
||||
var (
|
||||
// SlugUserNotFound is the slug whenever a user is not found by the provided identifier.
|
||||
SlugUserNotFound = NewSlug("user", "not_found")
|
||||
|
||||
// SlugUserNotActive is the slug whenever the user requires to be in state "active", but isn't.
|
||||
SlugUserNotActive = NewSlug("user", "not_active")
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrUserNotFound is an error that can be used when a user is not found by the provided identifier.
|
||||
ErrUserNotFound = func(err error, identifier string) error {
|
||||
return zerrors.CreateZitadelError(zerrors.KindNotFound, err, string(SlugUserNotFound), "user was not found", 1).
|
||||
WithDetails(zerrors.ErrorDetailsMap{"identifier": identifier})
|
||||
}
|
||||
|
||||
// ErrUserNotActive is an error that can be returned when a user needs to be active for the operation,
|
||||
// e.g. sign in, reactivation, etc. but has a different state.
|
||||
ErrUserNotActive = func(id, message string) error {
|
||||
return zerrors.CreateZitadelError(zerrors.KindPreconditionFailed, nil, string(SlugUserNotActive), message, 1).
|
||||
WithDetails(zerrors.ErrorDetailsMap{"id": id})
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user