mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-01 16:38:52 +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
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
"github.com/zitadel/zitadel/internal/zerrors"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
@@ -123,3 +124,32 @@ type sessionChanges interface {
|
||||
// SetMetadata adds or updates the metadata of the session.
|
||||
SetMetadata(metadata []*SessionMetadata) database.Change
|
||||
}
|
||||
|
||||
var (
|
||||
// SlugSessionNotFound is a slug used whenever a session is not found by the requested id.
|
||||
SlugSessionNotFound = NewSlug("session", "not_found")
|
||||
|
||||
// SlugSessionUserChange is a slug used when trying to change the user of an already authenticated session, which is not allowed.
|
||||
SlugSessionUserChange = NewSlug("session", "user_change")
|
||||
|
||||
// SlugSessionTokenInvalid is a slug used when the provided session token is invalid, either because it is malformed, expired or does not match the session.
|
||||
SlugSessionTokenInvalid = NewSlug("session", "token_invalid")
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrSessionNotFound is an error that can be returned when a session with the requested id was not found.
|
||||
ErrSessionNotFound = func(err error, id string) error {
|
||||
return zerrors.CreateZitadelError(zerrors.KindNotFound, err, string(SlugSessionNotFound), "session was not found", 1).
|
||||
WithDetails(zerrors.ErrorDetailsMap{"id": id})
|
||||
}
|
||||
|
||||
// ErrSessionUserChange is an error that can be returned when trying to change the user of an already authenticated session, which is not allowed.
|
||||
ErrSessionUserChange = func() error {
|
||||
return zerrors.CreateZitadelError(zerrors.KindInvalidArgument, nil, string(SlugSessionUserChange), "session was already authenticated with another user, you cannot change it to a different one", 1)
|
||||
}
|
||||
|
||||
// ErrSessionTokenInvalid is an error that can be returned whenever the provided (session) token is invalid for the intended session.
|
||||
ErrSessionTokenInvalid = func(err error) error {
|
||||
return zerrors.CreateZitadelError(zerrors.KindPermissionDenied, err, string(SlugSessionTokenInvalid), "The provided session token is invalid: either the token is malformed, expired or does not match the session", 1)
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user