Pārlūkot izejas kodu

models: rename ErrUserNotExist -> errors.UserNotExist

Unknwon 7 gadi atpakaļ
vecāks
revīzija
0ccd7c97ab

+ 2 - 1
cmd/serv.go

@@ -17,6 +17,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/setting"
 	http "github.com/gogits/gogs/routers/repo"
 )
@@ -153,7 +154,7 @@ func runServ(c *cli.Context) error {
 
 	owner, err := models.GetUserByName(ownerName)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			fail("Repository owner does not exist", "Unregistered owner: %s", ownerName)
 		}
 		fail("Internal error", "Fail to get repository owner '%s': %v", ownerName, err)

+ 2 - 1
models/action.go

@@ -20,6 +20,7 @@ import (
 	"github.com/gogits/git-module"
 	api "github.com/gogits/go-gogs-client"
 
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/setting"
 )
@@ -292,7 +293,7 @@ func (push *PushCommits) AvatarLink(email string) string {
 		u, err := GetUserByEmail(email)
 		if err != nil {
 			push.avatars[email] = base.AvatarLink(email)
-			if !IsErrUserNotExist(err) {
+			if !errors.IsUserNotExist(err) {
 				log.Error(4, "GetUserByEmail: %v", err)
 			}
 		} else {

+ 2 - 1
models/comment.go

@@ -15,6 +15,7 @@ import (
 
 	api "github.com/gogits/go-gogs-client"
 
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/markdown"
 )
 
@@ -95,7 +96,7 @@ func (c *Comment) loadAttributes(e Engine) (err error) {
 	if c.Poster == nil {
 		c.Poster, err = GetUserByID(c.PosterID)
 		if err != nil {
-			if IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				c.PosterID = -1
 				c.Poster = NewGhostUser()
 			} else {

+ 0 - 14
models/error.go

@@ -54,20 +54,6 @@ func (err ErrUserAlreadyExist) Error() string {
 	return fmt.Sprintf("user already exists [name: %s]", err.Name)
 }
 
-type ErrUserNotExist struct {
-	UID  int64
-	Name string
-}
-
-func IsErrUserNotExist(err error) bool {
-	_, ok := err.(ErrUserNotExist)
-	return ok
-}
-
-func (err ErrUserNotExist) Error() string {
-	return fmt.Sprintf("user does not exist [uid: %d, name: %s]", err.UID, err.Name)
-}
-
 type ErrEmailAlreadyUsed struct {
 	Email string
 }

+ 14 - 0
models/errors/user.go

@@ -17,6 +17,20 @@ func (err EmptyName) Error() string {
 	return "empty name"
 }
 
+type UserNotExist struct {
+	UserID int64
+	Name   string
+}
+
+func IsUserNotExist(err error) bool {
+	_, ok := err.(UserNotExist)
+	return ok
+}
+
+func (err UserNotExist) Error() string {
+	return fmt.Sprintf("user does not exist [user_id: %d, name: %s]", err.UserID, err.Name)
+}
+
 type UserNotKeyOwner struct {
 	KeyID int64
 }

+ 4 - 4
models/issue.go

@@ -90,7 +90,7 @@ func (issue *Issue) loadAttributes(e Engine) (err error) {
 	if issue.Poster == nil {
 		issue.Poster, err = getUserByID(e, issue.PosterID)
 		if err != nil {
-			if IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				issue.PosterID = -1
 				issue.Poster = NewGhostUser()
 			} else {
@@ -390,7 +390,7 @@ func (i *Issue) GetAssignee() (err error) {
 	}
 
 	i.Assignee, err = GetUserByID(i.AssigneeID)
-	if IsErrUserNotExist(err) {
+	if errors.IsUserNotExist(err) {
 		return nil
 	}
 	return err
@@ -595,7 +595,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
 	}
 
 	issue.Assignee, err = GetUserByID(issue.AssigneeID)
-	if err != nil && !IsErrUserNotExist(err) {
+	if err != nil && !errors.IsUserNotExist(err) {
 		log.Error(4, "GetUserByID [assignee_id: %v]: %v", issue.AssigneeID, err)
 		return nil
 	}
@@ -668,7 +668,7 @@ func newIssue(e *xorm.Session, opts NewIssueOptions) (err error) {
 
 	if opts.Issue.AssigneeID > 0 {
 		assignee, err := getUserByID(e, opts.Issue.AssigneeID)
-		if err != nil && !IsErrUserNotExist(err) {
+		if err != nil && !errors.IsUserNotExist(err) {
 			return fmt.Errorf("getUserByID: %v", err)
 		}
 

+ 7 - 7
models/login_source.go

@@ -296,7 +296,7 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR
 	username, fn, sn, mail, isAdmin, succeed := source.Cfg.(*LDAPConfig).SearchEntry(login, password, source.Type == LOGIN_DLDAP)
 	if !succeed {
 		// User not in LDAP, do nothing
-		return nil, ErrUserNotExist{0, login}
+		return nil, errors.UserNotExist{0, login}
 	}
 
 	if !autoRegister {
@@ -404,9 +404,9 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
 	if len(cfg.AllowedDomains) > 0 {
 		idx := strings.Index(login, "@")
 		if idx == -1 {
-			return nil, ErrUserNotExist{0, login}
+			return nil, errors.UserNotExist{0, login}
 		} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) {
-			return nil, ErrUserNotExist{0, login}
+			return nil, errors.UserNotExist{0, login}
 		}
 	}
 
@@ -425,7 +425,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
 		tperr, ok := err.(*textproto.Error)
 		if (ok && tperr.Code == 535) ||
 			strings.Contains(err.Error(), "Username and Password not accepted") {
-			return nil, ErrUserNotExist{0, login}
+			return nil, errors.UserNotExist{0, login}
 		}
 		return nil, err
 	}
@@ -465,7 +465,7 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
 func LoginViaPAM(user *User, login, password string, sourceID int64, cfg *PAMConfig, autoRegister bool) (*User, error) {
 	if err := pam.PAMAuth(cfg.ServiceName, login, password); err != nil {
 		if strings.Contains(err.Error(), "Authentication failure") {
-			return nil, ErrUserNotExist{0, login}
+			return nil, errors.UserNotExist{0, login}
 		}
 		return nil, err
 	}
@@ -525,7 +525,7 @@ func UserSignIn(username, password string) (*User, error) {
 				return user, nil
 			}
 
-			return nil, ErrUserNotExist{user.ID, user.Name}
+			return nil, errors.UserNotExist{user.ID, user.Name}
 
 		default:
 			var source LoginSource
@@ -554,5 +554,5 @@ func UserSignIn(username, password string) (*User, error) {
 		log.Warn("Failed to login '%s' via '%s': %v", username, source.Name, err)
 	}
 
-	return nil, ErrUserNotExist{user.ID, user.Name}
+	return nil, errors.UserNotExist{user.ID, user.Name}
 }

+ 2 - 1
models/pull.go

@@ -18,6 +18,7 @@ import (
 	"github.com/gogits/git-module"
 	api "github.com/gogits/go-gogs-client"
 
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/process"
 	"github.com/gogits/gogs/modules/setting"
 	"github.com/gogits/gogs/modules/sync"
@@ -101,7 +102,7 @@ func (pr *PullRequest) loadAttributes(e Engine) (err error) {
 
 	if pr.HasMerged && pr.Merger == nil {
 		pr.Merger, err = getUserByID(e, pr.MergerID)
-		if IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			pr.MergerID = -1
 			pr.Merger = NewGhostUser()
 		} else if err != nil {

+ 2 - 1
models/release.go

@@ -16,6 +16,7 @@ import (
 	"github.com/gogits/git-module"
 	api "github.com/gogits/go-gogs-client"
 
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/process"
 )
 
@@ -67,7 +68,7 @@ func (r *Release) loadAttributes(e Engine) (err error) {
 	if r.Publisher == nil {
 		r.Publisher, err = getUserByID(e, r.PublisherID)
 		if err != nil {
-			if IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				r.PublisherID = -1
 				r.Publisher = NewGhostUser()
 			} else {

+ 6 - 6
models/user.go

@@ -896,7 +896,7 @@ func getUserByID(e Engine, id int64) (*User, error) {
 	if err != nil {
 		return nil, err
 	} else if !has {
-		return nil, ErrUserNotExist{id, ""}
+		return nil, errors.UserNotExist{id, ""}
 	}
 	return u, nil
 }
@@ -912,7 +912,7 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
 	if err != nil {
 		return nil, err
 	} else if !has {
-		return nil, ErrUserNotExist{userID, ""}
+		return nil, errors.UserNotExist{userID, ""}
 	}
 	return GetUserByID(userID)
 }
@@ -920,14 +920,14 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
 // GetUserByName returns user by given name.
 func GetUserByName(name string) (*User, error) {
 	if len(name) == 0 {
-		return nil, ErrUserNotExist{0, name}
+		return nil, errors.UserNotExist{0, name}
 	}
 	u := &User{LowerName: strings.ToLower(name)}
 	has, err := x.Get(u)
 	if err != nil {
 		return nil, err
 	} else if !has {
-		return nil, ErrUserNotExist{0, name}
+		return nil, errors.UserNotExist{0, name}
 	}
 	return u, nil
 }
@@ -1005,7 +1005,7 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
 // GetUserByEmail returns the user object by given e-mail if exists.
 func GetUserByEmail(email string) (*User, error) {
 	if len(email) == 0 {
-		return nil, ErrUserNotExist{0, "email"}
+		return nil, errors.UserNotExist{0, "email"}
 	}
 
 	email = strings.ToLower(email)
@@ -1029,7 +1029,7 @@ func GetUserByEmail(email string) (*User, error) {
 		return GetUserByID(emailAddress.UID)
 	}
 
-	return nil, ErrUserNotExist{0, email}
+	return nil, errors.UserNotExist{0, email}
 }
 
 type SearchUserOptions struct {

+ 1 - 1
models/user_mail.go

@@ -177,7 +177,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
 	if err != nil {
 		return err
 	} else if !has {
-		return ErrUserNotExist{email.UID, ""}
+		return errors.UserNotExist{email.UID, ""}
 	}
 
 	// Make sure the former primary email doesn't disappear.

+ 4 - 3
modules/auth/auth.go

@@ -14,6 +14,7 @@ import (
 	"gopkg.in/macaron.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/setting"
 )
@@ -65,7 +66,7 @@ func SignedInID(ctx *macaron.Context, sess session.Store) int64 {
 	}
 	if id, ok := uid.(int64); ok {
 		if _, err := models.GetUserByID(id); err != nil {
-			if !models.IsErrUserNotExist(err) {
+			if !errors.IsUserNotExist(err) {
 				log.Error(2, "GetUserById: %v", err)
 			}
 			return 0
@@ -90,7 +91,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool)
 			if len(webAuthUser) > 0 {
 				u, err := models.GetUserByName(webAuthUser)
 				if err != nil {
-					if !models.IsErrUserNotExist(err) {
+					if !errors.IsUserNotExist(err) {
 						log.Error(4, "GetUserByName: %v", err)
 						return nil, false
 					}
@@ -125,7 +126,7 @@ func SignedInUser(ctx *macaron.Context, sess session.Store) (*models.User, bool)
 
 				u, err := models.UserSignIn(uname, passwd)
 				if err != nil {
-					if !models.IsErrUserNotExist(err) {
+					if !errors.IsUserNotExist(err) {
 						log.Error(4, "UserSignIn: %v", err)
 					}
 					return nil, false

+ 2 - 5
modules/context/org.go

@@ -10,6 +10,7 @@ import (
 	"gopkg.in/macaron.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/setting"
 )
 
@@ -49,11 +50,7 @@ func HandleOrgAssignment(ctx *Context, args ...bool) {
 	var err error
 	ctx.Org.Organization, err = models.GetUserByName(orgName)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
-			ctx.Handle(404, "GetUserByName", err)
-		} else {
-			ctx.Handle(500, "GetUserByName", err)
-		}
+		ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 		return
 	}
 	org := ctx.Org.Organization

+ 2 - 1
modules/context/repo.go

@@ -18,6 +18,7 @@ import (
 	"github.com/gogits/git-module"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/setting"
 )
 
@@ -169,7 +170,7 @@ func RepoAssignment(args ...bool) macaron.Handler {
 		} else {
 			owner, err = models.GetUserByName(ownerName)
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					if ctx.Query("go-get") == "1" {
 						earlyResponseForGoGetMeta(ctx)
 						return

+ 4 - 3
routers/api/v1/api.go

@@ -13,6 +13,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
 	"github.com/gogits/gogs/routers/api/v1/admin"
@@ -38,7 +39,7 @@ func repoAssignment() macaron.Handler {
 		} else {
 			owner, err = models.GetUserByName(userName)
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					ctx.Status(404)
 				} else {
 					ctx.Error(500, "GetUserByName", err)
@@ -137,7 +138,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 		if assignOrg {
 			ctx.Org.Organization, err = models.GetUserByName(ctx.Params(":orgname"))
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					ctx.Status(404)
 				} else {
 					ctx.Error(500, "GetUserByName", err)
@@ -149,7 +150,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 		if assignTeam {
 			ctx.Org.Team, err = models.GetTeamByID(ctx.ParamsInt64(":teamid"))
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					ctx.Status(404)
 				} else {
 					ctx.Error(500, "GetTeamById", err)

+ 5 - 4
routers/api/v1/repo/collaborators.go

@@ -8,13 +8,14 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 )
 
 func ListCollaborators(ctx *context.APIContext) {
 	collaborators, err := ctx.Repo.Repository.GetCollaborators()
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetCollaborators", err)
@@ -32,7 +33,7 @@ func ListCollaborators(ctx *context.APIContext) {
 func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
 	collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetUserByName", err)
@@ -58,7 +59,7 @@ func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
 func IsCollaborator(ctx *context.APIContext) {
 	collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetUserByName", err)
@@ -82,7 +83,7 @@ func IsCollaborator(ctx *context.APIContext) {
 func DeleteCollaborator(ctx *context.APIContext) {
 	collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetUserByName", err)

+ 3 - 2
routers/api/v1/repo/issue.go

@@ -11,6 +11,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
 )
@@ -86,7 +87,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
 		if len(form.Assignee) > 0 {
 			assignee, err := models.GetUserByName(form.Assignee)
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					ctx.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", form.Assignee))
 				} else {
 					ctx.Error(500, "GetUserByName", err)
@@ -152,7 +153,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
 		} else {
 			assignee, err := models.GetUserByName(*form.Assignee)
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					ctx.Error(422, "", fmt.Sprintf("assignee does not exist: [name: %s]", *form.Assignee))
 				} else {
 					ctx.Error(500, "GetUserByName", err)

+ 5 - 4
routers/api/v1/repo/repo.go

@@ -12,6 +12,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
 	"github.com/gogits/gogs/modules/setting"
@@ -80,7 +81,7 @@ func Search(ctx *context.APIContext) {
 func listUserRepositories(ctx *context.APIContext, username string) {
 	user, err := models.GetUserByName(username)
 	if err != nil {
-		ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
+		ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 		return
 	}
 
@@ -190,7 +191,7 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
 func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
 	org, err := models.GetOrgByName(ctx.Params(":org"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetOrgByName", err)
@@ -213,7 +214,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
 	if f.Uid != ctxUser.ID {
 		org, err := models.GetUserByID(f.Uid)
 		if err != nil {
-			if models.IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				ctx.Error(422, "", err)
 			} else {
 				ctx.Error(500, "GetUserByID", err)
@@ -280,7 +281,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
 func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
 	owner, err := models.GetUserByName(ctx.Params(":username"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Error(422, "", err)
 		} else {
 			ctx.Error(500, "GetUserByName", err)

+ 2 - 1
routers/api/v1/user/key.go

@@ -8,6 +8,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
 	"github.com/gogits/gogs/routers/api/v1/convert"
@@ -17,7 +18,7 @@ import (
 func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
 	user, err := models.GetUserByName(ctx.Params(name))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Status(404)
 		} else {
 			ctx.Error(500, "GetUserByName", err)

+ 2 - 1
routers/api/v1/user/user.go

@@ -10,6 +10,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/context"
 )
 
@@ -54,7 +55,7 @@ func Search(ctx *context.APIContext) {
 func GetInfo(ctx *context.APIContext) {
 	u, err := models.GetUserByName(ctx.Params(":username"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Status(404)
 		} else {
 			ctx.Error(500, "GetUserByName", err)

+ 2 - 1
routers/org/members.go

@@ -9,6 +9,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
@@ -100,7 +101,7 @@ func Invitation(ctx *context.Context) {
 		uname := ctx.Query("uname")
 		u, err := models.GetUserByName(uname)
 		if err != nil {
-			if models.IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
 				ctx.Redirect(ctx.Org.OrgLink + "/invitations/new")
 			} else {

+ 2 - 1
routers/org/setting.go

@@ -10,6 +10,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -113,7 +114,7 @@ func SettingsDelete(ctx *context.Context) {
 	org := ctx.Org.Organization
 	if ctx.Req.Method == "POST" {
 		if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
-			if models.IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
 			} else {
 				ctx.Handle(500, "UserSignIn", err)

+ 2 - 1
routers/org/teams.go

@@ -11,6 +11,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -73,7 +74,7 @@ func TeamsAction(ctx *context.Context) {
 		var u *models.User
 		u, err = models.GetUserByName(uname)
 		if err != nil {
-			if models.IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
 				ctx.Redirect(ctx.Org.OrgLink + "/teams/" + ctx.Org.Team.LowerName)
 			} else {

+ 3 - 2
routers/repo/http.go

@@ -22,6 +22,7 @@ import (
 	"gopkg.in/macaron.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
@@ -59,7 +60,7 @@ func HTTPContexter() macaron.Handler {
 
 		owner, err := models.GetUserByName(ownerName)
 		if err != nil {
-			ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
+			ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 			return
 		}
 
@@ -107,7 +108,7 @@ func HTTPContexter() macaron.Handler {
 		}
 
 		authUser, err := models.UserSignIn(authUsername, authPassword)
-		if err != nil && !models.IsErrUserNotExist(err) {
+		if err != nil && !errors.IsUserNotExist(err) {
 			ctx.Handle(http.StatusInternalServerError, "UserSignIn", err)
 			return
 		}

+ 4 - 11
routers/repo/pull.go

@@ -15,6 +15,7 @@ import (
 	"github.com/gogits/git-module"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -449,11 +450,7 @@ func ParseCompareInfo(ctx *context.Context) (*models.User, *models.Repository, *
 	} else if len(headInfos) == 2 {
 		headUser, err = models.GetUserByName(headInfos[0])
 		if err != nil {
-			if models.IsErrUserNotExist(err) {
-				ctx.Handle(404, "GetUserByName", nil)
-			} else {
-				ctx.Handle(500, "GetUserByName", err)
-			}
+			ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 			return nil, nil, nil, nil, "", ""
 		}
 		headBranch = headInfos[1]
@@ -719,7 +716,7 @@ func CompareAndPullRequestPost(ctx *context.Context, f form.NewIssue) {
 func parseOwnerAndRepo(ctx *context.Context) (*models.User, *models.Repository) {
 	owner, err := models.GetUserByName(ctx.Params(":username"))
 	if err != nil {
-		ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
+		ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 		return nil, nil
 	}
 
@@ -753,11 +750,7 @@ func TriggerTask(ctx *context.Context) {
 
 	pusher, err := models.GetUserByID(pusherID)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
-			ctx.Error(404)
-		} else {
-			ctx.Handle(500, "GetUserByID", err)
-		}
+		ctx.NotFoundOrServerError("GetUserByID", errors.IsUserNotExist, err)
 		return
 	}
 

+ 2 - 1
routers/repo/repo.go

@@ -16,6 +16,7 @@ import (
 	"github.com/gogits/git-module"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -47,7 +48,7 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User {
 	}
 
 	org, err := models.GetUserByID(uid)
-	if models.IsErrUserNotExist(err) {
+	if errors.IsUserNotExist(err) {
 		return ctx.User
 	}
 

+ 2 - 1
routers/repo/setting.go

@@ -14,6 +14,7 @@ import (
 	"github.com/gogits/git-module"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -311,7 +312,7 @@ func SettingsCollaborationPost(ctx *context.Context) {
 
 	u, err := models.GetUserByName(name)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Flash.Error(ctx.Tr("form.user_not_exist"))
 			ctx.Redirect(setting.AppSubUrl + ctx.Req.URL.Path)
 		} else {

+ 3 - 3
routers/repo/webhook.go

@@ -6,7 +6,6 @@ package repo
 
 import (
 	"encoding/json"
-	"errors"
 	"fmt"
 	"strings"
 
@@ -16,6 +15,7 @@ import (
 	api "github.com/gogits/go-gogs-client"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -468,7 +468,7 @@ func TestWebhook(ctx *context.Context) {
 		author, err := models.GetUserByEmail(commit.Author.Email)
 		if err == nil {
 			authorUsername = author.Name
-		} else if !models.IsErrUserNotExist(err) {
+		} else if !errors.IsUserNotExist(err) {
 			ctx.Flash.Error(fmt.Sprintf("GetUserByEmail.(author) [%s]: %v", commit.Author.Email, err))
 			ctx.Status(500)
 			return
@@ -477,7 +477,7 @@ func TestWebhook(ctx *context.Context) {
 		committer, err := models.GetUserByEmail(commit.Committer.Email)
 		if err == nil {
 			committerUsername = committer.Name
-		} else if !models.IsErrUserNotExist(err) {
+		} else if !errors.IsUserNotExist(err) {
 			ctx.Flash.Error(fmt.Sprintf("GetUserByEmail.(committer) [%s]: %v", commit.Committer.Email, err))
 			ctx.Status(500)
 			return

+ 5 - 8
routers/user/auth.go

@@ -12,6 +12,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -49,7 +50,7 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
 
 	u, err := models.GetUserByName(uname)
 	if err != nil {
-		if !models.IsErrUserNotExist(err) {
+		if !errors.IsUserNotExist(err) {
 			return false, fmt.Errorf("GetUserByName: %v", err)
 		}
 		return false, nil
@@ -113,7 +114,7 @@ func SignInPost(ctx *context.Context, f form.SignIn) {
 
 	u, err := models.UserSignIn(f.UserName, f.Password)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), SIGNIN, &f)
 		} else {
 			ctx.Handle(500, "UserSignIn", err)
@@ -286,11 +287,7 @@ func Activate(ctx *context.Context) {
 			return
 		}
 		if err := models.UpdateUser(user); err != nil {
-			if models.IsErrUserNotExist(err) {
-				ctx.Error(404)
-			} else {
-				ctx.Handle(500, "UpdateUser", err)
-			}
+			ctx.Handle(500, "UpdateUser", err)
 			return
 		}
 
@@ -351,7 +348,7 @@ func ForgotPasswdPost(ctx *context.Context) {
 
 	u, err := models.GetUserByEmail(email)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
+		if errors.IsUserNotExist(err) {
 			ctx.Data["Hours"] = setting.Service.ActiveCodeLives / 60
 			ctx.Data["IsResetSent"] = true
 			ctx.HTML(200, FORGOT_PASSWORD)

+ 4 - 11
routers/user/home.go

@@ -12,6 +12,7 @@ import (
 	"github.com/Unknwon/paginater"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
@@ -32,11 +33,7 @@ func getDashboardContextUser(ctx *context.Context) *models.User {
 		// Organization.
 		org, err := models.GetUserByName(orgName)
 		if err != nil {
-			if models.IsErrUserNotExist(err) {
-				ctx.Handle(404, "GetUserByName", err)
-			} else {
-				ctx.Handle(500, "GetUserByName", err)
-			}
+			ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 			return nil
 		}
 		ctxUser = org
@@ -71,7 +68,7 @@ func retrieveFeeds(ctx *context.Context, ctxUser *models.User, userID, offset in
 		if !ok {
 			u, err := models.GetUserByName(act.ActUserName)
 			if err != nil {
-				if models.IsErrUserNotExist(err) {
+				if errors.IsUserNotExist(err) {
 					continue
 				}
 				ctx.Handle(500, "GetUserByName", err)
@@ -406,11 +403,7 @@ func showOrgProfile(ctx *context.Context) {
 func Email2User(ctx *context.Context) {
 	u, err := models.GetUserByEmail(ctx.Query("email"))
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
-			ctx.Handle(404, "GetUserByEmail", err)
-		} else {
-			ctx.Handle(500, "GetUserByEmail", err)
-		}
+		ctx.NotFoundOrServerError("GetUserByEmail", errors.IsUserNotExist, err)
 		return
 	}
 	ctx.Redirect(setting.AppSubUrl + "/user/" + u.Name)

+ 2 - 5
routers/user/profile.go

@@ -12,6 +12,7 @@ import (
 	"github.com/Unknwon/paginater"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/setting"
@@ -26,11 +27,7 @@ const (
 func GetUserByName(ctx *context.Context, name string) *models.User {
 	user, err := models.GetUserByName(name)
 	if err != nil {
-		if models.IsErrUserNotExist(err) {
-			ctx.Handle(404, "GetUserByName", nil)
-		} else {
-			ctx.Handle(500, "GetUserByName", err)
-		}
+		ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
 		return nil
 	}
 	return user

+ 2 - 2
routers/user/setting.go

@@ -5,7 +5,6 @@
 package user
 
 import (
-	"errors"
 	"fmt"
 	"io/ioutil"
 	"strings"
@@ -14,6 +13,7 @@ import (
 	log "gopkg.in/clog.v1"
 
 	"github.com/gogits/gogs/models"
+	"github.com/gogits/gogs/models/errors"
 	"github.com/gogits/gogs/modules/base"
 	"github.com/gogits/gogs/modules/context"
 	"github.com/gogits/gogs/modules/form"
@@ -456,7 +456,7 @@ func SettingsDelete(ctx *context.Context) {
 
 	if ctx.Req.Method == "POST" {
 		if _, err := models.UserSignIn(ctx.User.Name, ctx.Query("password")); err != nil {
-			if models.IsErrUserNotExist(err) {
+			if errors.IsUserNotExist(err) {
 				ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), SETTINGS_DELETE, nil)
 			} else {
 				ctx.Handle(500, "UserSignIn", err)