From 751fe8b714f8ebd5fa915e893402776c4856d6c2 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 20 Dec 2024 10:05:29 -0800 Subject: Move some errors to their own sub packages (#32880) --- models/user/user.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'models/user/user.go') diff --git a/models/user/user.go b/models/user/user.go index bd92693b6e..72caafc3ba 100644 --- a/models/user/user.go +++ b/models/user/user.go @@ -788,6 +788,21 @@ func createUser(ctx context.Context, u *User, meta *Meta, createdByAdmin bool, o return committer.Commit() } +// ErrDeleteLastAdminUser represents a "DeleteLastAdminUser" kind of error. +type ErrDeleteLastAdminUser struct { + UID int64 +} + +// IsErrDeleteLastAdminUser checks if an error is a ErrDeleteLastAdminUser. +func IsErrDeleteLastAdminUser(err error) bool { + _, ok := err.(ErrDeleteLastAdminUser) + return ok +} + +func (err ErrDeleteLastAdminUser) Error() string { + return fmt.Sprintf("can not delete the last admin user [uid: %d]", err.UID) +} + // IsLastAdminUser check whether user is the last admin func IsLastAdminUser(ctx context.Context, user *User) bool { if user.IsAdmin && CountUsers(ctx, &CountUserFilter{IsAdmin: optional.Some(true)}) <= 1 { -- cgit v1.2.3