mirror of https://github.com/gogs/gogs.git
api/repo: improve migration error handling
parent
809db853fa
commit
9e3c83372f
|
@ -93,19 +93,6 @@ func (err ErrUserHasOrgs) Error() string {
|
|||
return fmt.Sprintf("user still has membership of organizations [uid: %d]", err.UID)
|
||||
}
|
||||
|
||||
type ErrReachLimitOfRepo struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
func IsErrReachLimitOfRepo(err error) bool {
|
||||
_, ok := err.(ErrReachLimitOfRepo)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrReachLimitOfRepo) Error() string {
|
||||
return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
|
||||
}
|
||||
|
||||
// __ __.__ __ .__
|
||||
// / \ / \__| | _|__|
|
||||
// \ \/\/ / | |/ / |
|
||||
|
|
|
@ -21,6 +21,19 @@ func (err RepoNotExist) Error() string {
|
|||
return fmt.Sprintf("repository does not exist [id: %d, user_id: %d, name: %s]", err.ID, err.UserID, err.Name)
|
||||
}
|
||||
|
||||
type ReachLimitOfRepo struct {
|
||||
Limit int
|
||||
}
|
||||
|
||||
func IsReachLimitOfRepo(err error) bool {
|
||||
_, ok := err.(ReachLimitOfRepo)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ReachLimitOfRepo) Error() string {
|
||||
return fmt.Sprintf("user has reached maximum limit of repositories [limit: %d]", err.Limit)
|
||||
}
|
||||
|
||||
type InvalidRepoReference struct {
|
||||
Ref string
|
||||
}
|
||||
|
|
|
@ -1019,7 +1019,7 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err
|
|||
// CreateRepository creates a repository for given user or organization.
|
||||
func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository, err error) {
|
||||
if !owner.CanCreateRepo() {
|
||||
return nil, ErrReachLimitOfRepo{owner.MaxRepoCreation}
|
||||
return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
|
||||
}
|
||||
|
||||
repo := &Repository{
|
||||
|
|
|
@ -610,8 +610,9 @@ func getVerifyUser(code string) (user *User) {
|
|||
if b, err := hex.DecodeString(hexStr); err == nil {
|
||||
if user, err = GetUserByName(string(b)); user != nil {
|
||||
return user
|
||||
} else if !errors.IsUserNotExist(err) {
|
||||
log.Error(2, "GetUserByName: %v", err)
|
||||
}
|
||||
log.Error(4, "user.getVerifyUser: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -250,7 +250,7 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
|
|||
case addrErr.IsPermissionDenied:
|
||||
ctx.Error(422, "", "You are not allowed to import local repositories")
|
||||
case addrErr.IsInvalidPath:
|
||||
ctx.Error(422, "", "Invalid local path, it does not exist or not a directory.")
|
||||
ctx.Error(422, "", "Invalid local path, it does not exist or not a directory")
|
||||
default:
|
||||
ctx.Error(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
|
||||
}
|
||||
|
@ -273,7 +273,12 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
|
|||
log.Error(2, "DeleteRepository: %v", errDelete)
|
||||
}
|
||||
}
|
||||
ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
|
||||
|
||||
if errors.IsReachLimitOfRepo(err) {
|
||||
ctx.Error(422, "", err)
|
||||
} else {
|
||||
ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ func Create(ctx *context.Context) {
|
|||
|
||||
func handleCreateError(ctx *context.Context, owner *models.User, err error, name, tpl string, form interface{}) {
|
||||
switch {
|
||||
case models.IsErrReachLimitOfRepo(err):
|
||||
case errors.IsReachLimitOfRepo(err):
|
||||
ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.RepoCreationNum()), tpl, form)
|
||||
case models.IsErrRepoAlreadyExist(err):
|
||||
ctx.Data["Err_RepoName"] = true
|
||||
|
|
Loading…
Reference in New Issue